list - 如何检查列表中的所有网络元素是否显示
问题描述
我想验证“更多信息”页脚部分下的“关于我们”、“联系我们”和“常见问题”文本链接是否显示
我怎样才能检查它?我是否必须获取每个列表 web 元素的 xpath,然后检查它是否显示在网页上?或一次所有网络元素的列表,然后跟踪for循环?
还帮助我为“关于我们”元素编写 xpath
解决方案
您可以一次验证全部,也可以单独验证,尝试下面的代码,它将获取所有选项,验证这些选项是否存在并检查它们是否显示:
// Get all the options using the below line
List<WebElement> elements = driver.findElements(By.xpath("//div[@class='footer-section']//a"));
// Check they are present or not?
if(elements.size() > 0) {
System.out.println("=> The Options are present...");
} else {
System.out.println("=> The Options are nor present...");
}
// Check they are displayed or not?
for(WebElement element : elements) {
System.out.println(element.getText()+" is displayed? "+element.isDisplayed());
}
如果要单独验证,则需要执行以下操作:
driver.findElement(By.xpath("//div[@class='footer-section']//a[text()='About Us']")).isDisplayed();
推荐阅读
- ios - Swift iOS -CollectionView 如何将单元格滚动到屏幕外
- r - 条形顶部的 R geom_bar 和 facet_grid 标签
- firebase - 如何将集合从 Mongodb 迁移到 Cloud Firestore
- reactjs - 我不明白为什么我的 propTypes 检查没有在这个类上运行
- javascript - 使用选择选项输入 js 更改正文背景颜色
- java - 只有 1 个线程访问 RestController 方法
- php - 没有错误,但没有“行动”
- ssl - URL Rewrite Force to https 除一个域外
- c - 使用 rand() 生成 N 个数字且不重复的算法
- javascript - 移动视图菜单问题?