Setting Path on Windows
For Windows XP: More…
I was getting this error : Invalid xpath [3]: XPath parse error when I used xpath xpath=id(‘**IIIIIIHHHHHHHHHHHH’)[@href]. The solution is xpath=//a[@id='**IIIIIIHHHHHHHHHHHH'][@href]. Here I used //a as this was the tag id for the element.
There is a great need today to validate the meta tags and the contents on a website for google indexing and SEO. Here is an example of using Xpath in selenium to verify the meta tags and the contents.
I have used xpath to verify if a particular string is available on the web page. Using the same concept I am now able to verify if google analytics code is available on the web page.
Here is the example:
Say my google analytics code is something like this:
[JavaScript]script type=“text/javascript”
try {
var pageTracker = _gat._getTracker(“UA-222222-3″);
pageTracker._trackPageview();
} catch(err) {}script
[/JavaScript]
The xpath for that is //script[@type="text/javascript"][contains(text(), 'UA-222222-3')]
Then you use verifyElementPresent in selenium. I hope this will be useful for you all.
<tr> <td>verifyElementPresent</td> <td>//script[@type='text/javascript'][contains(text(), 'UA-222222-3')]</td> <td></td> </tr>
Submitted by Puddupakkam Pavandeep
When element doesn’t contain any id and name, using xpath to find the element is very important for writing selenium test. I list some sample locate for the element which doesn’t contain id or name.