webdriver - Selenium WebDriver - 如何验证多行文本

标签 webdriver verify multiline

我有一个包含以下内容的 html 页面:

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

如何使用一个 webdriver 命令验证上面的所有静态文本?

我试过这些,但都不起作用:(
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')]"))

有谁知道怎么做?

最佳答案

你可以做:

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

随意使用您选择的定位器而不是 By.id。

基本上,任何 WebElement 的 getText() 都会返回节点的文本内容,去除所有 HTML 标记和注释。

关于webdriver - Selenium WebDriver - 如何验证多行文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10697678/

相关文章:

javascript - 页面加载时 Quill 编辑器内的格式化文本

.net - 用文本行填充多行编辑框的方法是什么

javascript - Selenium:如何点击 javascript 按钮

javascript - 谁能帮我解释使用 selenium webdriver 进行图像验证的 javascript 代码?

Python/Selenium - Chrome Web 驱动程序,单击操作

xpath - Selenium :在searchContext中查找元素

mysql:显示警告宣布的截断或修改的数据

openssl - 在 Bash 中验证 PEM 证书有错误,但返回代码正常

java - java中如何显示带有换行符的文本

php - 在 PHP 中通过发送方和接收方之间的公钥验证私钥的签名