我需要单击浏览器通知的第一个按钮,该按钮在单击“删除愿望 list ”按钮后出现。 该按钮如下;
<a href="/account/wishlistupdate?mainAction=delete&wishlistId=2547474" class="btn btn-danger btn-sm" onclick="return confirm('This action cannot be undone. Are you sure you want to delete this wishlist?')" style="" xpath="1">Delete wishlist</a>
单击此按钮将打开浏览器通知。
我尝试过alert.accept(),但对我不起作用。
public HomePage editWishlist(){
click(edit_button); // By edit_button = By.xpath("//div[@class='btn-edit-text']");
click(deleteWishlist_button); // By deleteWishlist_button = By.linkText("Delete wishlist");
try {
Thread.sleep(1500);
} catch(InterruptedException e) {
System.out.println("got interrupted!");
}
Alert alert = driver.switchTo().alert();
alert.accept();
return this;
}
我该如何处理这个问题?
最佳答案
这是一个Javascript确认警报
,您可以通过切换
到它然后接受
来接受它:
driver.switchTo().alert().accept();
与点击cancel
类似,您可以调用方法dismiss()
关于javascript - 如何使用 Selenium 和 Java 接受 "This action cannot be undone. Are you sure you want to delete this wishlist"弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58022813/