selenium chrome driver select certificate popup confirmation not working

后端 未结 5 865
旧时难觅i
旧时难觅i 2020-12-10 05:09

I am automating tests using selenium chromewebdriver 3.7. Whenever I lauch the site, I get a certificate selection popup like the one below

However I am not able to

相关标签:
5条回答
  • 2020-12-10 06:01

    You can also skip being prompted when a certificate is missing, invalid, or self-signed.

    You would need to set acceptInsecureCerts in DesiredCapabilities and pass that when you create a driver instance.

    for example, in Python:

    from selenium import webdriver
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    
    caps = DesiredCapabilities.CHROME.copy()
    caps['acceptInsecureCerts'] = True
    driver = webdriver.Chrome(desired_capabilities=caps)
    
    0 讨论(0)
  • 2020-12-10 06:05

    If still actual, I had same issue on Mac, and solution was simple:

    • for chrome is set AutoSelectCertificateForUrls policy like that:

      defaults write com.google.Chrome AutoSelectCertificateForUrls -array-add -string '{"pattern":"[*.]example.com","filter":{"ISSUER":{"CN":"**cert issuer**"}, "SUBJECT":{"CN": "**cert name**"}}}'
      
    • for safari:

      security set-identity-preference -c "**cert name**" -s "**example.com**"
      

    then use it in code like subprocess.call() in python

    0 讨论(0)
  • 2020-12-10 06:08

    I had the same problem and I was able to solve it by using the robot, creating function for the url and passing it to a different thread.

        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();
           }
    
    0 讨论(0)
  • 2020-12-10 06:09

    One suggestion would be, use Sikuli to click on OK button in the certificate.

    Steps:

    1. Take screenshot of OK button and save it.
    2. Download sikuli-script.jar and add it to Project's Build path.
    3. Take a screenshot of the UI Element to be clicked and save it locally.
    4. Add the following code to the test case.

      Screen s=new Screen(); s.click(“image name”);

    Other functions Sikuli provides can be found here.

    0 讨论(0)
  • 2020-12-10 06:10

    I also had problems with accepting the warning for using a signed certificate. The solution of @eskoba worked like a charm. The functions are NOT final, because I let the enter button press for 10 times. I made this, because the webdriver needs a long time until it actually calls the url. In the meantime he starts pressing already.

    In 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()
    
    0 讨论(0)
提交回复
热议问题