Xpath

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: ,

Using regular expressions in xpath Selenium 

Here is an example where I have used regular expressions in xpath.
This article includes a code sample that demonstrates how you can use the starts-with XML Path Language (XPath) string function to implement this requirement.

More…

By Pavandeep Puddupakkam on October 14, 2010 | Selenium RC | 2 comments
Tags: ,

How to use Verifyelementpresent in Selenium 

You can use selenium.IsElementPresent(“element”) to see if a particular element is present on the web page. This is a very powerful function in selenium as you can use it with a if condition.
In this example I am first checking if there is an element //td[@class='Selenium'] on the web page. If yes then I click the element //td[@class='Selenium'] and continue checking the other conditions.

More…

By Pavandeep Puddupakkam on July 21, 2010 | Selenium RC | 1 comment
Tags: , ,

Handling Selenium error – verifyXpathCount 

Here is an error that I got when I executed the following verifyXpathCount command
<tr>
<td>verifyXpathCount</td>
<td>xpath=//span[@id='ctl00_contentSection_GoogleAFSRight']/div/div[@class='SingleVertical']/a[@class='Heading' and @href]</td>
<td>4</td>
</tr>

More…

Selenium – verifyXpathCount 

verifyXpathCount(xpath, pattern)
Generated from getXpathCount(xpath)
Arguments:
* xpath – the xpath expression to evaluate. do NOT wrap this expression in a ‘count()’ function; we will do that for you.
Returns:
the number of nodes that match the specified xpath

More…