I have this little piece of code that just checks for a particular text at a location on the page and if that text is found, it will check for something else..Here is the snippet:
if (!selenium.isTextPresent(“//div[contains(concat(”,@class,”),’contentLg’)]/h2″)) {
System.out.println(“The About Us text is not present”);
}
else {
verifyEquals(aboutText, “//*[@class=’content contentLg’]/p[3]”);
}
Here is the generated output that I am trying to grab the text “About Us” from. I am trying to see if the page has “About Us” text (which is in
tag). If there is, just match one of the “p” tag with predefined text:
<!-- MAIN CONTENT CONTAINER -->
<!-- MAIN CONTENT CONTAINER -->
About Us
<p><span class="faqQuestion">About The Site</span><br>
this is about the site</p>
<p>test one two three</p>
<p>this test test test test test test</p>
<br>
<p><span class="faqQuestion">About Company</span><br>
This is about the company</p>
<p>fafasdfsafasdfafasfasfasasfasfasfafsasf</p>
<p>afasfasdfasdffafffffffffffffffffffffffffffffffffffffffffffffffffffffffffff</p>
<br>
<p><span class="faqQuestion">Helping Businesses</span><br>
Helping business
<a href="/businesses.asp">click here</a> to learn more.</p>
Here is what I wrote in a CustomSelenium class that extends DefaultSelenium.
Just call this before you call isTextPresent. This is a Selenium bug.