【发布时间】:2020-04-04 16:57:43
【问题描述】:
我需要单击一个按钮,该按钮可能以 50% 的几率出现,决定使用 try/catch 和 findElementBy。然而try/catch 不起作用,我遇到了一个例外。也许有更有效的方法来处理该按钮?
driver.manage().timeouts().implicitlyWait(5000, TimeUnit.MILLISECONDS);
WebDriverWait wait = new WebDriverWait(driver,5);
try {
WebElement element = driver.findElement(By.xpath("buttonXpath"));
element.click();
}
catch (NoSuchElementException e){ }
【问题讨论】:
-
你能显示异常堆栈跟踪吗?请同时添加您的导入,尤其是 NoSuchElementException 之一。
-
您遇到的异常是什么?
NoSuchElementException?
标签: java selenium try-catch nosuchelementexception