XPath

Validating the text from a text box using Selenium RC 

Here is the html code input id=”qu” and the text in the text input box is Selenium Wiki.


To validate the text from a text box using Selenium RC you will have to use the Selenium command selenium.getValue(). This will get the value in the location input id=”qu”.
selenium.getValue(“//input[@id='qu']“)

More…

By Pavandeep Puddupakkam on September 8, 2011 | Selenium RC, XPath | 2 comments
Tags: , ,

Using Xpath when you have new line text 

Here is an example where there are new lines and have to validate if the exact text is displayed in the correct order using xpath.

User-agent: *
Disallow: /clickthrough.html
Disallow: /details.html
Disallow: /post-sendtofriend.html

Use normalize-space(), which will throw away the leading and trailing whitespace characters (and condense repeating spaces in the middle of the text into a single space), so that you can compare the normalized text() and use to filter in a predicate.
Here is the xpath code to validate the above text

try
{
selenium.getText("//test[normalize-space()]").Equals("pass the string here");
}
catch(Exception)
{
}

By Pavandeep Puddupakkam on July 13, 2011 | XPath | A comment?
Tags: , ,

Using regular expression in Selenium 

Here is the xpath I want to use regular expression.
Code with out using regular expression:
Assert.IsTrue(selenium.IsElementPresent(“ctl00_5hh5_g5656_675gffg042f_tbSearch”));
Code using regular expression:
Assert.assertTrue(selenium.isElementPresent(“css=input[id$='tbSearch']“));

More…

By Pavandeep Puddupakkam on July 4, 2011 | XPath | A comment?
Tags: ,

How to use contains to get the attribute value in xpath 

This is one my best finds so far and would like to share it with you. Here is an example that shows you how to use the xpath contains to build a xpath using part of the attribute value. This can be used when there are elements with the same id or text value.

More…

By Pavandeep Puddupakkam on November 19, 2010 | XPath | 5 comments
Tags:

Alternative to using xpath contains text() in Selenium 

Here is an alternative to using contains text() in xpath command

script type="text/javascript"
try {
var pageTracker = _gat._getTracker("UA-222222-3");
pageTracker._trackPageview();
} catch(err) {}script

More…

By Pavandeep Puddupakkam on September 15, 2010 | Selenium RC, XPath | 2 comments
Tags: , ,

How to dynamically generate xpath by xpath axis 

xpath axis How to dynamically generate xpath by xpath axis

xpath axis image


We can dynamically generate xpath for a control on a web page by xpath axis.
For example, we want to locate “Add ” button by its corresponding category name, say “test” or “driving instructor”.

More…

By BiLi on September 14, 2010 | XPath | 2 comments
Tags: