java - isDisplayed() 方法执行时间太长
问题描述
我正在研究Java Selenium项目并使用isDisplayed()
方法来验证页面上是否显示某些元素,并且执行每个这样的方法大约需要45秒,有什么建议为什么它可能需要这么长时间,可以吗?在框架级别指定了一些等待?注意:不是我创建的框架,我只是在更新它。\
@FindBy(xpath = "//input[@id='productLIGrpTermDeal_chkPartySlf']//following-sibling::div")
List<WebElement> GroupTermDealerLifeInsuranceSelf1;
public boolean verify_Icon_Is_Not_Displayed_() throws Exception {
try {
log.debug("Validate Icon is not Displayed");
Assert.assertEquals(0, GroupTermDealerLifeInsuranceSelf1.size());
System.out.println("Icon is not Displayed");
log.info("Icon is validated successfully || Pass");
return true;
} catch (Exception e) {
System.err.println("Icon is Displayed");
log.error("Not able to Validate Icon is Displayed || Fail" + e.getMessage());
return false;
}
}
解决方案
您可以修改 XPath 查询以将List的大小限制为 1(或您在测试中使用的最大值)。可以通过在定位器末尾添加position() 函数来实现,例如:
@FindBy(xpath = "//input[@id='productLIGrpTermDeal_chkPartySlf']//following-sibling::div/*[position()<=1]")
一旦应用此更改,定位WebElement的时间将与DOM中的匹配数成比例减少。
更多信息:XPath 运算符和函数
推荐阅读
- python-3.x - 使用 NLP 创建文本摘要
- python - 如何同时对 X_train 和 y_train 应用增强
- c# - 调用异步函数。一个习俗。c#中的线程
- javascript - 我如何不显示价格超过的元素???从容器
- c - 编译后立即在 cmd 上运行程序(vscode 上的 Code Runner 插件)
- reactjs - 如何让 react-app 将“1n”识别为 BigInt
- r - ggplot2 错误消息:seq.default(range[1], range[2], length.out = nframes) 中的错误:'from' 必须是有限数
- java - Feign REST 客户端:FactoryBean 在创建对象时抛出异常
- android - 根据另一个 RecyclerView 项目位置滚动 RecyclerView
- ios - 新应用安装时调用新领域迁移