0
votes

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)

1

1 Answers

0
votes

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')]");