Handling 'choose a digital certificate' with selenium webdriver chrome

。_饼干妹妹 提交于 2019-12-21 03:45:48

问题


When I open a page with selenium webdriver I get a chrome dialog box "Choose certificate". The default certificate is the right one so I only have to click OK button. But I have problem with this. I have python code:

drv = webdriver.Chrome()   
drv.get("https://example.com/login")

and after that I want to do something like:

drv.switch_to_alert().accept()

or

drv.switch_to_alert().send_keys(Keys.TAB)
drv.switch_to_alert().send_keys(Keys.SPACE)

The problem is that the code stops executing on line drv.get("https://example.com/login"). Webdriver is waiting for page to load. And before that line there is no chrome dialog box.

How can I handle this?


回答1:


You'll have to use something like AutoIT:

http://www.autoitscript.com/site/autoit/

Why you ask? It's an OS dialog, which Selenium does not and probably never will handle, so you'll have to turn to other solutions (in C# you should use native Win32 API methods to click the button for instance).




回答2:


Certificates are managed by the OS, not the browser. Delete all but the necessary certificate from your browser's certificate store and then configure the browser to automatically select the certificate when only one certificate is present. You could also create a browser profile and have your program launch this profile or avoid testing over HTTPS.




回答3:


before handling anything here, add below so it will not get frozen as soon as you navigate/triggert the certificate pop up. remeber to add the correct waittime back later.

 getDriver().manage().timeouts().pageLoadTimeout(1000, TimeUnit.MILLISECONDS); 

after this, then you can try using keyboard or autoIt whatever .



来源:https://stackoverflow.com/questions/14960084/handling-choose-a-digital-certificate-with-selenium-webdriver-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!