Getting Invalid Xpath Error while using getAttribute method in Selenium - xpath

I am getting invalid xpath error while using getAttribute method... though I am able to locate the image using same xpath in firepath.
I am using below method..
String imgAtt = StartServer.browser.getAttribute("//img[contains(#alt,'Selenium IDE Logo')]");
Error:
Exception in thread "main" com.thoughtworks.selenium.SeleniumException: ERROR: Invalid xpath [2]: //img[contains(
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:112)

Maybe you need to use fn:contains:
String imgAtt = StartServer.browser.getAttribute("//img[fn:contains(#alt,'Selenium IDE Logo')]");
Or declare the default function namespace. But I'm not familiar enough with Selenium to tell you how to do that.
Also the XPath you call in getAttribute will not return an attribute. It will be an <img> element. It's possible that function is throwing an exception due to the invalid parameter type. If you want just the attribute, use:
String imgAtt = StartServer.browser.getAttribute("//img/#alt[contains(.,'Selenium IDE Logo')]");

Related

IllegalArgument Exception : Unable to compile

I am getting IlleagalArgument Exception while retreiving Xpath for a particular node
I need to retrieve the below webpage link which follows the title WebPages ,I tried using the below expression but it is not able compile (Please see the comment section for the html )
page.getNode("//h3[. = 'Webpages:']/following-sibling::/ul[#class='list-entity-locations']/li/a/text()")
This is what I tried but got Exception
java.lang.IllegalArgumentException: Unable to compile
The right syntax is following-sibling::ul, not following-sibling::/ul.
To looking into html which you have posted there is no : text inside <h3>...</h3> tag.
Try the below code.
//h3[. = 'Webpages']/following-sibling::ul[#class='list-entity-locations']/li/a/text()

How to fix "Cannot read property 'apply' of undefined" trying to get the location using Protractor?

I'm trying to get an element's location using the Protractor (v6.0.0) method call getLocation(), however I'm getting the following exception:
TypeError: Cannot read property 'apply' of undefined
at <Jasmine>
at actionFn (/usr/lib/node_modules/protractor/built/element.js:95:44)
at <Jasmine>
at actionResults.getWebElements.then(/usr/lib/node_modules/protractor/built/element.js:468:44)
at <Jasmine>
at ElementArrayFinder.applyAction_(/usr/lib/node_modules/protractor/built/element.js:466:29)
Any clue how to resolve the issue?
Actually my code is really simple.
it('should compare login page with a baseline', async () => {
let input = element(by.id('mat-input-1'));
await input.getLocation();
});
I expect the coordinates of the input which has id mat-input-1, but unfortunately I'm getting that exception.
Protractor's CHANGELOG.md has a link to the selenium-webdriver CHANGELOG, it lists:
Changes for W3C WebDriver Spec Compliance
Replaced WebElement.getSize() and WebElement.getLocation() with a
single method, WebElement.getRect().
So it looks like you should use .getRect().
Now for Protractor 6 itself, this is clearly an issue with documentation. We recommend using 5.4.2 for now.

BaseX XQuery gives error message „Context is undeclared“

The following xquery code runs into the error „Context is undeclared“. I am using BaseX v9.1.2.
How is it possible that this error happens there?
In your return statement, there is no context for the XPath to be applied. Use the $el variable bound in your loop:
return <key-val><key>{ data($el/as:SERVICE-INSTANCE-REFS/...

Can not extract value in SOAPUI property transfer using xPath and namespaces

I try to extract value from xml in Property Transfer I use xPath:
declare namespace S="http://www.w3.org/2003/05/soap-envelope"
declare namespace ns7="http://schemas.BIGBANK.pl/" xmlns="http://schemas.BIGBANK.pl/"
/S:Envelope/S:Body/ns7:Document/ns7:QueryIPR/ns7:IPIList/ns7:PI/ns7:PI/ns7:cId/
and i get error:
cId [net.sf.saxon.trans.XPathException: Required item type of first operand of '/' is node(); supplied value has item type xs:string]
I set source of transfer as previous step (that return valid XML), property Response and path language XPath
have no idea how to fix it in SoapUI (in pure java it is much more easier)
Ok, my mistake
At the second line I have:
declare namespace ns7="http://schemas.BIGBANK.pl/" xmlns="http://schemas.BIGBANK.pl/"
And if you work with pure XML it is OK attribute set. But in SoapUI it should be:
declare namespace ns7="http://schemas.BIGBANK.pl/"
An now it works fine.

HP UFT - WebElement cannot be found even after using correct 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."

Resources