【发布时间】:2019-12-24 10:20:04
【问题描述】:
这是一个登录测试场景。 有两个用户。他们是有效用户和无效用户。 弹出确定点击正在测试中。
问题 ----->
如果---->(如果不存在元素)---- print("成功登录"),
else ----> (如果元素存在) ----- 弹出确定点击。与其他用户一起登录。
没有这样的元素情况,我不能这样做。
错误
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"html/body/div/div/div[3]/button[1]"}
(Session info: chrome=79.0.3945.88)
代码
WebElement temp444 = driver.findElement(By.xpath("html/body/div/div/div[3]/button[1]"));
System.out.println(temp444.getSize());
if(temp.getSize()!=null){
temp.click(); // ----> It's working!
}
else {
System.out.println("good working"); // ----> It isn't working.
}
【问题讨论】:
标签: java html selenium testing