如果动态发生任何错误,则错误消息会显示在站点上。就我而言,如果发生错误,会出现弹出窗口,我需要单击“确定”按钮。
问题是,使用所有 Selenium 技巧,我无法避免 NoSuchElementException 或“无法单击元素”异常。期望:如果出现错误弹出,点击确定,如果没有,继续跳过这些ifs。我正在遵循这种方法:
PageFactory 元素和方法。
@FindBy(id='locator')
List<WebElement> errorElement1;
@FindBy(id='locator2')
List<WebElement> errorElement2;
Usage:
if(errorElement1.size() > 0) {
errorElement1.get(0).click();
}
if(errorElement2.size() > 0) {
errorElement2.get(0).click();
}
问题是,如果我使用 errorElement1.isDisplayed 方法,我会得到 NosuchElementException。
我尝试了所有可以在这里找到的技巧,到目前为止没有成功。谢谢!