HP UFT - WebElement cannot be found even after using correct xpath - xpath

I am new to UFT. I have a long "complex" xpath that finds precisely one element in chrome browser developer tools. When I use the same xpath in uft, the tool complains that the xpath is not in the object repository. Why does this happen and how do I fix it ?
This is what the xpath looks like:
//div[#class='a b c']//div[#class='p-q r-s']//div[#class='m n']//button[contains(text(), 'yes')]
I have to use such complex xpath because there are no ID attributes in this part of the page or any other 1-2 attributes which can uniquely identify the element.
Please help.
EDIT: My Vbscript code looks similar to this code:
Dim aButtonLoc
aButtonLoc = "//div[#class='a-b c-d-e g']" & _
"//div[#class='p-q r-s-t']//div[#class='uv w-x']" & _
"//button[contains(text(), 'Yes')]"
Error message: The {full xpath here} object was not found in the Object Repository. Check the Object Repository to confirm that the object exists or to find the correct name for the object.

There is an error in my aButtonLoc locator. It should have xpath mentioned, like this: aButtonLoc = "xpath:=//d...etc."

Related

UFT Report is broken

Lately we are getting more and more often confronted with problems with UFT. Many API components can't executed anymore, but there are 2 possible outputs:
UFT gives a message from "object reference not set to an instance of an object" without even starting the test, let alone reporting. The Output Pane contains the following message:
Start
object reference not set to an instance of an object
End
when we execute a test using ALM we get a KeyNotFoundException:
2020-01-22 12:04:38,039 HP.ST.Fwk.ReporterFWK.Reporter [ 1] ERROR Problem in writing Step Xml
System.Collections.Generic.KeyNotFoundException: The specified key was not listed in the dictionary.
For System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key)
for HP.ST.Fwk.ReportCreator.QTPEngine.Utils.GetNodeInfo(Object stepId, XmlDocument xmlDoc, IReportDataContainer reportData)
for HP.ST.Fwk.ReportCreator.QTPEngine.CPNodeWriter.CreateOuterCheckpointsXML(Object stepId, XmlDocument doc, XmlNode node, String innerCheckpointsFileName, String childId, IReportDataContainer reportDataContainer)
for HP.ST.Fwk.ReportCreator.QTPEngine.CPNodeWriter.CreateFileForReferencedValues(XmlDocument doc, XmlNode& reportNode, Object stepId, IReportDataContainer reportDataContainer)
for HP.ST.Fwk.ReportCreator.QTPEngine.CPNodeWriter.CreateXmlFile(Dictionary`2 nodeInfo, Object stepId, XmlDocument doc, IReportDataContainer IReportDataContainer)
for HP.ST.Fwk.ReporterFWK.Reporter.WriteStepToDisk(String stepId, String fileName)
for HP.ST.Fwk.ReporterFWK.Reporter.<>c__DisplayClass36_0.<FlushReport>b__0()
for System.Threading.Tasks.Task.InnerInvoke()
for System.Threading.Tasks.Task.Execute()
We've tried every direction, reinstalling UFT, patching... all to no avail. The behavior seems to be present in both UFT 14.53 and UFT 14.53 Patch 1 - 3. UFT One is also affected.
The UFT support could not help us at all, you know how they are.

Nightwatch.js - assert.containsText I'm looking for a string but got empty (null)

Here is a spinet of my code:
browser
.waitForElementPresent('(//*[#class="textsize-xlarge"])[1]',5000)
.assert.containsText('(//*[#class="textsize-xlarge"])[1]', 'TEST-69554083978')
I want to verify that an element has a string using assert.containsText().
So I'm trying to check if the class textsize-xlarge contains text
"TEST-69554083978"
Visually I can see that it does but nightwatch returns an error message saying expected
"TEST-69554083978" got ""
Can anyone please tell me what I'm doing wrong here and point me in the right directions?
browser.useXpath(); // xpath will be used as the locating strategy so
all the selectors you pass should be xpath selectors
browser.useCss(); // switches back to css selector locator should be
your xpath
let locator = "[#class='textsize-xlarge']//*[contains(text(),'TEST-69554083978')]";
// Please modify above locator as I am not aware of your DOM but I can help further if you need any help in Xpath
return browser
.useXpath()
.waitForElementPresent(locator)
.assert.elementPresent(locator);
you can learn about node assertions: Node Assertions

SoapUI XPath assertion with wildcards

Is there a way to use a wildcard inside an assertion in a XPath test with SoapUI?
I took a look at SoapUI's documentation and they say you can do something like this
<path1>
<path2>*</path2>
</path1>
I checked the 'Allow Wildcards' checkbox.
My question is : I want to assert my date starts with 2012-08-22 but i dont care about the minutes and seconds. I guess my the expression should be something like 2012-08-22* but it doesn't work.
What you are doing sounds like it should work. Here is a quick example i cooked up using a rest service from http://www.geonames.org/export/web-services.html#timezone. I'm using the demo they have supplied
http://api.geonames.org/timezone?lat=47.01&lng=10.2&username=demo
output is
<geonames>
<timezone tzversion="tzdata2012c">
<countryCode>AT</countryCode>
<countryName>Austria</countryName>
<lat>47.01</lat>
<lng>10.2</lng>
<timezoneId>Europe/Vienna</timezoneId>
<dstOffset>2.0</dstOffset>
<gmtOffset>1.0</gmtOffset>
<rawOffset>1.0</rawOffset>
<time>2012-07-25 04:39</time>
<sunrise>2012-07-25 05:50</sunrise>
<sunset>2012-07-25 21:00</sunset>
</timezone>
</geonames>
If you do an xpath match on the result and use the select from current button you get
//geonames/timezone/time
2012-07-25 04:39
If you update this to
//geonames/timezone/time
2012-07-25*
this will work fine and when updating the rest request with a new lat and lng the assertion will still pass since it is not checking the time. If this doesn't help, please supply your full assertion and maybe i could help more.
*note: for soap requests, make sure to declare the namespace and then use the proper format
//ns1:message
It will be sort of a pain, but here is what you can do:
1) Figure out an Xpath 'base' using the assertion tab (sounds like you are here already). I used this public site to test against: http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl
I used the CornerPoints method with 'hawaii' as the single param.
I created this 'base' xpath:
declare namespace ns1='http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl';
declare namespace SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/';
declare namespace SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/';
/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:CornerPointsResponse/listLatLonOut
(it will write the declare statements for you if you click declare)
(which you can test out in the assertions window)
2) Create a Properties step
3) Create a Property transfer step
4) Create a groovy script
5) add a property... i called mine misc
6) add a transfer step
* transfer from the CornerPoints - Request 1 --- Response
* paste the Xpath stuff in the box under the 'transfer from'
* Transfer to your property
(You can test with the little play button)
7) Add something like this to your groovy script:
def x = context.expand( '${Properties#misc}' )
def parts = x.tokenize(',')
for (def part in parts)
{
log.info(part)
if (part.startsWith("-153"))
log.info("good")
}
In the groovy step you can do anything you need to get at your (partial) data. The sample code I added gets lat/lons out of a long line wrapped in CDATA and then checks for just the starting part of some of the data.. just an example.
Remember that you can use groovy and java string methods:
http://groovy.codehaus.org/groovy-jdk/java/lang/String.html
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html
More groovy tips:
http://www.soapui.org/Scripting-Properties/tips-a-tricks.html

Selenium WebDriver issue with By.cssSelector

I have an element whose html is like :
<div class="gwt-Label textNoStyle textNoWrap titlePanelGrayDiagonal-Text">Announcements</div>
I want to check the presence of this element. So I am doing something like :
WebDriver driver = new FirefoxDriver(profile);
driver.findElement(By.cssSelector(".titlePanelGrayDiagonal-Text"));
But its not able to evaluate the CSSSelector.
Even I tried like :
By.cssSelector("gwt-Label.textNoStyle.textNoWrap.titlePanelGrayDiagonal-Text")
tried with this as well :
By.cssSelector("div.textNoWrap.titlePanelGrayDiagonal-Text")
Note : titlePanelGrayDiagonal-Text class is used by only this element in the whole page. So its unique.
Contains pseudo selector I can not use.
I want to identify only with css class.
Versions: Selenium 2.9 WebDriver
Firefox 5.0
When using Webdriver you want to use W3C standard css selectors not sizzle selectors like you may be used to using in jquery. In your example you would want to use:
driver.findElement(By.cssSelector("div[class='titlePanelGrayDiagonal-Text']"));
From reading over your post what you should do since that class is unique is just do a FindElement(By.ClassName("titlePanelGrayDiagonal-Text"));
Also the CssSelector doesn't handle the contains keyword it was something that the w3 talked about but never added.
I haven't used css selectors, but this is the xpath selector I would use:
"xpath=//div[#class='gwt-Label textNoStyle textNoWrap titlePanelGrayDiagonal-Text']"
The css selector should then probably be something like
"css=div[class='gwt-Label textNoStyle textNoWrap titlePanelGrayDiagonal-Text']"
Source: http://release.seleniumhq.org/selenium-remote-control/0.9.2/doc/dotnet/Selenium.html
Did you ever tried following code,
By.cssSelector("div#gwt-Label.textNoStyle.textNoWrap.titlePanelGrayDiagonal-Text");
I believe using a wildcard in CSS would be more helpful. Something as follows
driver.findElement(By.cssSelector("div[class$='titlePanelGrayDiagonal-Text']");
This will look into the class attribute and see what that attribute is ending with. Since your class attribute is ending with "titlePanelGrayDiagonal-Text" string, the added '$' in the css statement will find the element and then you can perform whatever action you're trying to perform.

how to extract data using jtidy and xpath

i have to extract d company name and face value from
http://money.rediff.com/companies/20-microns-ltd/15110088
i noticed that this task could be accomplished using xpath api.
since this is an html page, i am using jtidy parser.
this is the xpath for the face value which i have to extract.
/html/body/div[4]/div[6]/div[9]/div/table/tbody/tr[4]/td[2]
This is my code
URL oracle = new URL("http://money.rediff.com/companies/20-microns-ltd/15110088");
URLConnection yc = oracle.openConnection();
InputStream is = yc.getInputStream();
is = oracle.openStream();
Tidy tidy = new Tidy();
tidy.setQuiet(true);
tidy.setShowWarnings(false);
Document tidyDOM = tidy.parseDOM(is, null);
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xPath = xPathFactory.newXPath();
String expression = "/html";
XPathExpression xPathExpression = xPath.compile(expression);
Object result = xPathExpression.evaluate(tidyDOM,XPathConstants.NODESET);
System.out.println(result.toString());
please guide me further, because, i cannot find a right solution for the above
Try not to use "full" xpaths.
//div[#id='leftcontainer']//div[9]//table//tr[4]/td[2]
is better than
/html/body/.../.../.../.../.../...
Most HTML pages are not valid or even well-formed. So the DOM structure may change when processed by "real-world HTML parsers". For example, a <tbody> may be inserted under <table> if there isn't one. Things are worse when different HTML parsers generate different DOM trees so one XPath may be valid for one parser, but not the other. I would rather use "wildcards" like table//tr[4] instead of table/tbody/tr[4] or table/tr[4] so that I can forget about <tbody>. Such expressions are more robust when used against the messy real-world HTML pages.
You can use Firepath, a plugin for Firebug which is then a plugin for Firefox, to debug XPath expressions.
p.s. You can try my JHQL (http://github.com/wks/jhql) project for exactly this task. You will like it if you have more pages to extract data from.

Resources