softAssert失败后无法找到元素

问题描述 投票:0回答:1

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

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个回答
0
投票

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

更确切地说:WebDriver.findElement(By)根据docs抛出NoSuchElementException。

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

© www.soinside.com 2019 - 2024. All rights reserved.