selenium chrome driver select certificate popup confirmation not working
Solution 1
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();
}
Solution 2
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()
Solution 3
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
Related videos on Youtube
user4237435
Updated on June 04, 2022Comments
-
user4237435 almost 2 years
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 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
-
deepak almost 5 yearsCan you explain, flow of this call ?
-
Jonathan Benn over 4 yearsWhere does the
robot
come from? I assume you mean the Selenium Robot class? -
Jonathan Benn over 4 yearsOups, the
Robot
class comes from AWT -
Gin over 4 yearsGreat answer! For a clearer definite, some important import goes like: import threading import pyautogui then define a browser i.e. browser = webdriver.Chrome(executable_path = 'chromedriver.exe PATH'); then you can put above code into work. One more comment here is that you can put a time.sleep(10) in the threaded_function2 so that it would allow 10 seconds for example to let the url load.
-
forkdbloke almost 4 yearscan you please explain this?
-
Alexey Kuptsov over 3 yearsThe policy can be enabled also via registry and other approaches in multiple operating systems. ``` See the policy docs chromium.org/administrators/…
-
Alexey Kuptsov over 3 yearsThis is how I configured this in a
.reg
file: ``` [HKEY_CURRENT_USER\SOFTWARE\Policies\Google\Chrome\AutoSelectCertificateForUrls] "1"="{\"pattern\":\"example.com\",\"filter\":{\"ISSUER\":{\"CN\":\"example.com\"}, \"SUBJECT\":{\"CN\":\"Alex McSubjectUser\"}}}" ``` -
Alexey Kuptsov over 3 yearsIt seems that the answer
AutoSelectCertificateForUrls
is more actual at the moment. -
matandked over 3 years
AutoSelectCertificateForUrls
seems to be not a good option if we want to use different certificates in our tests. Maybe changing values ofAutoSelectCertificateForUrls
dynamically during tests, before running browser, could be a workaround? However, I am afraid that it could require higher user permissions to edit registry.