qa_enq
qa_enq

Reputation: 51

Selenium WebDriver - how to verify multiple lines text

I have an html page with following contents:

    <center> 
          This is Login page. 
          <br> 
          Please click below link to Login.
          <br> 
          <a href="xxx">Login</a> 
    </center>

How can I verify all the static text above using one webdriver command?

I tried these but none of it works :(

driver.findElement(By.xpath("//*[contains(.,'This is Login page.<br>Please click below link to Login')]"))
driver.findElement(By.xpath("//*[contains(.,'This is Login page.\nPlease click below link to Login')]"))

Anyone know how to do it?

Upvotes: 5

Views: 28795

Answers (4)

Sri Janya
Sri Janya

Reputation: 1

You can do with "\n"

return getText(supportText).contains("Information:" + "\n" +
    "This page is for use by the TECHNICAL TEAM only. Following links will be active, only if you have access (subscription) to those modules.");

Upvotes: -1

Bibek
Bibek

Reputation: 64

How to find the texts if the texts has space inbetween them.

      <br> 
        <br/>
      Please click below link to Login.
      <br> 
      <a href="xxx">Login</a> 
</center>

Upvotes: -1

Arran
Arran

Reputation: 25056

This is more a limitation of XPath than Selenium.

I do not see why you are using the global XPath selector there, a better XPath selector would be:

By.XPath("//center");

If it's the only "center" tag on the page, or even:

By.XPath("//center[contains(text(), 'This is a Login page'")

The /r and /n characters will be retained if you do it through code instead of blindly searching for it in XPath.

Upvotes: 1

Ashwin Prabhu
Ashwin Prabhu

Reputation: 7624

You can do:

webDriver.findElement(By.id("<ID of center tag>")).getText().contains("This is Login page.Please click below link to Login.Login");

Feel free to use a locator of your choice instead of By.id.

Basically getText() of any WebElement returns the textual content of the node, stripped of all the HTML tags and comments.

Upvotes: 4

Related Questions