我为 Firefox 驱动程序编写了相同的代码,它在那里工作正常,但在 Chrome 驱动程序中不起作用。
driver.get("https://the-internet.herokuapp.com");
Thread.sleep(2000);
driver.findElement(By.xpath("//*[@id=\"content\"]/ul/li[3]/a")).click();
Thread.sleep(5000);
Alert alert = driver.switchTo().alert();
Thread.sleep(100);
alert.dismiss();
最佳答案
在 Chrome 中,警报会阻止事件循环。您可以通过以下方式解决这个问题:
driver.executeScript("window.alert = () => null");
关于java - 警报在 chrome 中不起作用,但在 firefox 中起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55665641/