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?
You can do: webDriver. findElement(By.id("<ID of center tag>")). getText().
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With