Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium chrome driver select certificate popup confirmation not working

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

However I am not able to click on the OK button. These are the options I have tried

 //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();

All my trials have failed. How can I click on OK on this popup window? This is the closest solution I found which is not working Link here

like image 964
user4237435 Avatar asked Mar 27 '18 11:03

user4237435


3 Answers

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()
like image 112
chainstair Avatar answered Oct 18 '22 00:10

chainstair


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

like image 40
Bidonus UA Avatar answered Oct 18 '22 01:10

Bidonus UA


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();
       }
like image 26
eskoba Avatar answered Oct 18 '22 01:10

eskoba