我使用selenium chromewebdriver 3.7自动化测试.每当我浏览网站时,我都会获得一个类似于
以下的证书选择弹出窗口
但是我无法单击“确定”按钮.这些是我尝试过的选项
//I have tried getWindowHandle like this
String handle= driver.getWindowHandle();
this.driver.switchTo().window(handle);
//I have alos tried switching and accept
driver.switchTo().alert().accept();
//I have also tried to force the enter key like this
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
// I also tried this way
Scanner keyboard = new Scanner(System.in);
keyboard.nextLine();
我的所有试验都失败了.如何在此弹出窗口中单击“确定”?
这是我发现的最接近的解决方案,它不起作用Link here
最佳答案 我遇到了同样的问题,我可以通过使用机器人来解决它,为url创建函数并将其传递给不同的线程.
Runnable mlauncher = () -> {
try {
driver.get(url);
} catch (Exception e) {
e.printStackTrace();
}
};
public void myfunction {
try {
Thread mthread = new Thread(mlauncher);
mthread.start
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
} catch (Exception e) {
e.printStackTrace();
}