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

use*_*435 7 java testing selenium automated-tests selenium-webdriver

我正在使用Selenium chromewebdriver 3.7自动化测试。每当我浏览该网站时,都会出现如下所示的证书选择弹出窗口在此处输入图片说明

但是,我无法单击“确定”按钮。这些是我尝试过的选择

 //I have tried getWindowHandle like this  
 String  handle= driver.getWindowHandle();
        this.driver.switchTo().window(handle);
Run Code Online (Sandbox Code Playgroud)
//I have alos tried switching and accept
 driver.switchTo().alert().accept();
Run Code Online (Sandbox Code Playgroud)
//I have also tried to force the enter key like this
 robot.keyPress(KeyEvent.VK_ENTER);
 robot.keyRelease(KeyEvent.VK_ENTER);
Run Code Online (Sandbox Code Playgroud)
 // I also tried this way
 Scanner keyboard = new Scanner(System.in);
 keyboard.nextLine();
Run Code Online (Sandbox Code Playgroud)

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

cha*_*air 9

我在接受使用签名证书的警告时也遇到了问题。@eskoba 的解决方案非常有效。这些功能不是最终的,因为我按了 10 次 Enter 按钮。我这样做是因为网络驱动程序需要很长时间才能真正调用该网址。与此同时,他已经开始施压了。

在Python中

def threaded_function():
    #Calls the website
    browser.get(url)

def threaded_function2():
    #Presses 10 times
    for i in range(0,10):
        pyautogui.press('enter')

#Calling the website and pressing 10 times in the same time
thread2 = Thread(target = threaded_function2)
thread2.start()

thread = Thread(target = threaded_function)
thread.start()
Run Code Online (Sandbox Code Playgroud)


小智 5

如果仍然存在,我在 Mac 上遇到了同样的问题,解决方案很简单:

  • 对于 chrome,设置的AutoSelectCertificateForUrls策略如下:

    defaults write com.google.Chrome AutoSelectCertificateForUrls -array-add -string '{"pattern":"[*.]example.com","filter":{"ISSUER":{"CN":"**cert issuer**"}, "SUBJECT":{"CN": "**cert name**"}}}'
    
    Run Code Online (Sandbox Code Playgroud)
  • 对于野生动物园:

    security set-identity-preference -c "**cert name**" -s "**example.com**"
    
    Run Code Online (Sandbox Code Playgroud)

然后在代码中使用它,就像 subprocess.call()在Python中一样


esk*_*oba 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();
       }
Run Code Online (Sandbox Code Playgroud)