org.openqa.selenium.InvalidSelectorException Error on a link click

2,746 views
Skip to first unread message

jyo rani

unread,
Apr 12, 2012, 8:21:33 PM4/12/12
to webdriver

int id =1234;
driver.findElement(By.xpath("//a[contains(@href, '/servlet/PServlet?
ID='"+serviceOid+"'&page=viewProjectDetails')]")).click(); //error on
this line


My source code
<a class ="cp" href ="/servlet/PServlet?
ID=1234&page=viewProjectDetails">service text</a>

============================


org.openqa.selenium.InvalidSelectorException: findElement execution
failed;
Unable to locate an element with the xpath expression //
a[contains(@href, '/servlet/PServlet?
ID='1234'&page=viewProjectDetails')] because of the following error:
Error: INVALID_EXPRESSION_ERR: DOM XPath Exception 51 (WARNING: The
server did not provide any stacktrace information)
Command duration or timeout: 94 milliseconds
For documentation on this error, please visit:
http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '2.17.0', revision: '15546', time: '2012-01-16
17:11:34'
System info: os.name: 'Windows 2003', os.arch: 'x86', os.version:
'5.2', java.version: '1.6.0_26'
Driver info: driver.version: RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:
39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:
27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

Tarun Kumar

unread,
Apr 13, 2012, 12:51:46 AM4/13/12
to webd...@googlegroups.com
Could you first test your xPath locator on Firebug or chrome console?
You could hard code the variable values in your xPath locator for sake of testing. Looks like your element locator is not valid.

Ranjith Manne

unread,
Apr 13, 2012, 2:43:58 AM4/13/12
to webd...@googlegroups.com
Hi Jyo,

try this X-path:   //a[contains(text(),'service text')]



My source code
<a class ="cp" href ="/servlet/PServlet?
ID=1234&page=viewProjectDetails">service text</a>

Note: In some of the cases, that ID will change dynamically for each and every login, so better to use visible text of the link.


Regards,
Ranjith.



--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.


Singh, Rakesh

unread,
Apr 13, 2012, 3:04:42 AM4/13/12
to webd...@googlegroups.com

You can use xpath checker, a firefox plugin to validate uniqueness of xpath on a particular page. Its really a great tool to increase test robustness.

 

Regards

Rakesh

Øystein Torvund

unread,
Apr 13, 2012, 5:00:59 AM4/13/12
to webd...@googlegroups.com, webd...@googlegroups.com
Or you could use firepath. A even better plugin, but for firebug an firefox. 

Austin
Reply all
Reply to author
Forward
0 new messages