Selenium webdriver 不显示关于无创元素的错误

问题描述

我尝试在页面上查找文本 driver.findElement(By.xpath("//label[contains(text(),'Some text')]"));

我知道该文本未显示页面中。但系统接受测试为成功。

为什么系统不显示关于 NoSuchElementException 的错误

解决方法

您不会像不点击driver.findElement(By.xpath("//label[contains(text(),'Some text')]"));或其他东西那样使用 driver.findElement(By.xpath("//label[contains(text(),'Some text')]")).click(); 的结果。
调用 driver.findElement(By.xpath("//label[contains(text(),'Some text')]")); 会返回 null,但您不会以任何方式断言或验证结果。