java - 不显示验证按钮
问题描述
我尝试了以下解决方案来验证该按钮是否未针对特定用户组显示。这些解决方案均无效。我的代码没有这样的元素异常。如果还有什么我可以尝试的,请告诉我。
try {
boolean btnPresence = driver.findElement(By.linkText("/html/body/div/div/div/main/div[2]/div[2]/div/form/button")).isDisplayed();
}
catch (org.openqa.selenium.NoSuchElementException e)
{
return;
}
}
Assert.assertTrue(driver.findElement(By.xpath("/html/body/div/div/div/main/div[2]/div[2]/div/form/button")).isDisplayed());
if (driver.findElement(By.xpath("/html/body/div/div/div/main/div[2]/div[2]/div/form/button")).isDisplayed()) {
System.out.println("Fail! Submit button is displayed for a CMS Admin on the ORC TA Form.");}
else {
System.out.println("Pass!!- Submit Button is not displayed for CMS Admin on the ORC TA Form");
}
boolean elePresent = driver.findElement(By.xpath("/html/body/div/div/div/main/div[2]/div[2]/div/form/button")).isDisplayed();
boolean elePresent = driver.findElement(By.xpath("/html/body/div/div/div/main/div[2]/div[2]/div/form/button")).isDisplayed();
boolean exist = driver.findElement(By.xpath("/html/body/div/div/div/main/div[2]/div[2]/div/form/button")).size() == 0;
解决方案
您可以检查元素是否存在:
public boolean existsElement_byXpath(String xpath) {
try {
driver.findElement(By.xpath(xpath));
} catch (NoSuchElementException e) {
return false;
}
return true;
}
推荐阅读
- c# - 如何在 web.config 的部分属性中使用 appsettings 值
- java - 从云 Firestore 中的一个集合中获取所有文档?
- python - 如何在 Django 模型中添加变量
- ios - 哪个通知会触发 textViewDidChange?
- ruby-on-rails-4 - Rails NoMethodError:BigDecimal 的未定义新方法:Class
- mysql - 特定结果上 WHERE 子句的 SQL 提升约束
- r - 使用 R 根据条件获取特定字段和其旁边的单元格值
- reactjs - 使用 React Hooks 进行无限递归
- c - 扩展共享内存 C shmget
- android - 检测 Recyclerview 行是否与 FloatingActionButton 重叠