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']“)
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)
{
}
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']“));
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.
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