smriti
smriti

Reputation: 1144

Selenium verify text or link on the web page

If i have to check a 'xyz' text present in header of the web page & the 'xyz' is present in body of the page.on the use of this function.it will return true ,which is not correct..

selenium.isTextPresent("xyz");

Same question for link presence check.

selenium.isLinkPresent("link=xyz");

Please suggest me what is the best way to verify the text/link on the page through selenium.

Upvotes: 1

Views: 9744

Answers (1)

Vaman Kulkarni
Vaman Kulkarni

Reputation: 3451

You can use XPath to narrow down your search. For e.g. if you have XML like

 <MyXmlDoc>
    <Header>
        <TextNode>Hello World</TextNode>
        <A href="http://www.google.com"">Google</A>
    </Header>

    <Body>
        <TextNode>Hello World</TextNode>
        <A href="http://www.google.com"">Google</A>
    </Body>
 </MyXmlDoc>

To check if text Hello World is present in the <Header> you can use selenium.isElementPresent("//Header/TextNode[.='Hello World']");

OR

To check if text Hello World is present in the <Body> you can use selenium.isElementPresent("//Body/TextNode[.='Hello World']");

Similarly goes for Anchor (<A>) for <A> in <Header> selenium.isElementPresent("//Header/A[.='Google']");

And

for <A> in <Body> selenium.isElementPresent("//Body/A[.='Google']");

Hope this helps

Upvotes: 4

Related Questions