【问题标题】:Unable to find element after softAssert failsoftAssert 失败后无法找到元素
【发布时间】:2018-06-08 06:31:34
【问题描述】:

即使其中一个软断言失败,测试也会继续进行。 但在我的情况下,我的测试在软断言失败后停止,因为找不到下一个测试元素。

softAssert.assertTrue(p.OtsPage.fName().getAttribute("readonly").equals("true"), "field Name is Editable", "field Name is Read Only");
softAssert.assertTrue(p.OtsPage.fEditValue().isEnabled(), "field Edit Value is not Editable", "field Edit Value is Editable");

这可以正常工作,但如果我设置:

softAssert.assertFalse(p.OtsPage.fName().getAttribute("readonly").equals("true"), "field Name is Editable", "field Name is Read Only");
softAssert.assertFalse(p.OtsPage.fEditValue().isEnabled(), "field Edit Value is not Editable", "field Edit Value is Editable");

我收到以下错误消息:

org.openqa.selenium.NoSuchElementException。 第二次软断言!!!

然后测试停止。

环境:Selenium 3.5 + geckodriver + Mozilla 56.0.1。

【问题讨论】:

    标签: java selenium firefox assertions geckodriver


    【解决方案1】:

    这看起来不像断言的问题,因为正如你提到的第二行正在运行但它抛出异常。您的问题可能在这里:p.OtsPage.fEditValue().isEnabled()

    更准确地说:NoSuchElementException 是由WebDriver.findElement(By) 根据docs 抛出的。

    您可能在您的fEditValue() 函数中运行findElement(),您应该在那里搜索问题。确保该函数中选择器表示的元素在您运行它的那一刻确实存在于页面上。

    【讨论】:

      猜你喜欢
      • 2019-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-14
      • 2020-06-14
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多