if (!parent.equals(child_window)) {
driver.switchTo().window(child_window);
String title = driver.switchTo().window(child_window).getTitle();
j++;
System.out.println(j + " " + title);
try {
driver.switchTo().window(child_window).findElement(By.cssSelector("button.reply_button.js-only")).click();
Thread.sleep(9000);
} catch (NoSuchElementException ignored) {
System.out.println("No Element found");
continue;
} catch (StaleElementReferenceException ignoredxx) {
System.out.println("No Element found");
continue;
}
点击按钮打开弹出窗口。它工作,但当在页面上找不到按钮时,我收到此错误
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:
。我试图将continue语句放在catch块中,但它根本不起作用。
答案 0 :(得分:0)
尝试以下代码;
try {
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(By.cssSelector("button.reply_button.js-only")));
driver.switchTo().window(child_window).findElement(By.cssSelector("button.reply_button.js-only")).click();
}