小编典典

selenium chrome 驱动程序选择证书弹出确认不起作用

selenium

我正在使用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();

我所有的尝试都失败了。如何在此弹出窗口上单击“确定”?这是最接近的解决方案,我发现这是不工作的链接
在这里Linkhere


阅读 726

收藏
2020-06-26

共1个答案

小编典典

我遇到了同样的问题,我能够通过使用机器人,为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();
       }
2020-06-26