my dog learned polymorphism*
The moose likes Testing and the fly likes problem with my xpath in selenium. getting a invalid xpath error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "problem with my xpath in selenium. getting a invalid xpath error" Watch "problem with my xpath in selenium. getting a invalid xpath error" New topic
Author

problem with my xpath in selenium. getting a invalid xpath error

linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86
This is the location of my image which needs to be clicked.

//test10.abcd.com:7080/collab/chat/iconclose.gif

this is my xpath for the above image

By.xpath("//img[@src='//test10.tutorvista.com:7080/collab/chat/iconclose.gif"))


how can i correct my xpath?


do i need to write the tablerow and Division also to get to the element?
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86
This is my complete html for the image location

<table class="userSpanTb1">
<tbody>
<tr>
<td style="text-align : right; ">
<img class="close_button src="//test10.abcd.com:7080/collab/chat/iconclose.gif alt=close tittle=close this sesssion">
Brian Burress
Ranch Hand

Joined: Jun 30, 2003
Posts: 122
linda dinda wrote:This is the location of my image which needs to be clicked.

//test10.abcd.com:7080/collab/chat/iconclose.gif

this is my xpath for the above image

By.xpath("//img[@src='//test10.tutorvista.com:7080/collab/chat/iconclose.gif"))


how can i correct my xpath?


linda dinda wrote:
<img class="close_button src="//test10.abcd.com:7080/collab/chat/iconclose.gif alt=close tittle=close this sesssion">


I see several issues with the information.
1) The server in the xpath (test10.tutorvista.com:7080) does not match the url you indicate is the location (//test10.abcd.com:7080). You will never have a match.
2) The XPath expression is not valid - there is an open single qutoe and a closing double quote (i.e. not balanced) and no end bracket ']'
3) The html you posted does not look right. The class value has no end quote, the src tag has no end quote, the title lacks a begin quote, etc.
4) If you do re-post it I'll also suggest you post it through the end table tag (i.e. you'll want it in that form to use the tester link I refer to below).


linda dinda wrote:
how can i correct my xpath?



I suggest you look into a tester tool via some local java code or even use a web site such as thisXPathTester to assess your expressions. I have used both a site like this and local java code which reads the html or xml and then allows me to see the path behavior.

You may want to review some of the tutorials functions and so forth at w3schools. There is a lot of great information there and I learned a lot from the examples and even picked up on some functions and approaches to help make the expressions a little more solid such as use of the "contains" function as opposed to the entire literal. In your example, the server may change when in test vs. prod, for example, and if your XPath looked for an image where the src contained 'collab/chat/iconclose.gif' then the server would not matter.
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86
Thanks
 
Don't get me started about those stupid light bulbs.
 
subject: problem with my xpath in selenium. getting a invalid xpath error
 
Similar Threads
possible to instantiate Inner Class by itself
Tomcat showing error
unable to tcpmon a web service consumer
whats wrong with my code ?
could someone help?