-1

I am trying to automate a task which has to be done about 50 to 100 times a day. What I want to achieve is to open the corresponding website, login using a certificate, fill in two fields and click on submit.

I can figure out how to open the website and fill in the correct fields with the data using find element by xpath. However, I cannot manage to automate the login with the certificate. The login via the certificate is a pop-up within Google Chrome where I have to click OK or press the enter button (the machine I'm working on has only 1 certificate so it's automatically selected). The issue is that the login pop-up does not seem to be part of Chrome, I cannot find the xpath of the "OK" button.

At the moment I have the following code:

from selenium import webdriver
import time

driver = webdriver.Chrome()
driver.get('https://example.com')

Does anyone know in what direction I should move foreward?

Thanks!

Bart
  • 11
  • 2
  • 1
    In the interest of content quality, duplicate questions aren't permitted here. Please research your inquiry before posting in accordance with [ask]. This is a duplicate of [How to make Selenium WebDriver select client certificates dynamically without visually detecting the popup](https://stackoverflow.com/questions/47013742/how-to-make-selenium-webdriver-select-client-certificates-dynamically-without-vi) – esqew Jan 24 '22 at 15:09
  • TL;DR: Selenium does not support the manipulation of these dialogs, likely due to security implications of Selenium itself and the fact that these interstitials are popped by the OS. You may find some luck using another library to attach to and manipulate this window, but it will be extremely unlikely that Selenium itself will get you there. – esqew Jan 24 '22 at 15:10
  • @esqew the topic you shared does not answer my question. However, I've found a way around it by automatically selecting a certificate on a specific url. Source and credits: https://gist.github.com/IngussNeilands/3bbbb7d78954c85e2e988cf3bfec7caa – Bart Feb 02 '22 at 12:48
  • @Bart Please officially answer your own question and provide the solution as a cut and paste of code. The link is useful now, but might go away in the future. – Garet Jax Feb 02 '22 at 13:47
  • @GaretJax thanks for the comment, I've pasted the solution in the thread. – Bart Feb 03 '22 at 09:12

2 Answers2

1

Resolved the issue by defining what certificate to select on a specific website. This resolves the pop-up issue and will auto-login each time. From github:

"If you are using Google Chrome and Client SSL Cert and you are tired of constantly selecting certificates, try this:

  1. Download and extract Chrome policy templates from here: http://dl.google.com/dl/edgedl/chrome/policy/policy_templates.zip
  2. Start the Local Group Policy Editor: Start > Run > gpedit.msc > OK
  3. Right-click on Computer Policy > Computer Configuration > Administrative Templates and choose Add/Remove Templates…
  4. Click Add…, choose policy_templates\windows\adm\en-US\chrome.adm (from the already downloaded and extracted policy templates) and click Open (Note: if your Windows language is different from en-US choose the chrome.adm from the respective language folder)
  5. Navigate to Local Computer Policy > Computer Configuration > Administrative Templates > Classic Administrative Templates (ADM) > Google > Google Chrome > Content Settings
  6. Double-click on Automatically select client certificates for these sites
  7. Click Enabled
  8. Click Show… in the Options pane
  9. Consecutively add the following lines:

{"pattern":"https://[*.]example.com","filter":{"ISSUER":{"CN":"example.com"}}}

  1. Click OK
  2. Re-launch Chrome
  3. Done. No more annoying pop-ups!"

original source: https://gist.github.com/IngussNeilands/3bbbb7d78954c85e2e988cf3bfec7caa

Bart
  • 11
  • 2
-1

Can you just do a time.sleep(10) and then send a keyDown? i.e. wait until you can assume that the popup has appeared, then send an Enter key to the screen?

You can make this more concrete by sending enter every 5 seconds until your screen finds some xPath that appears

  • Unfortunately, this is not correct. Selenium's keyboard emulation is unlikely to work in this context for security reasons - this dialog is popped by the OS itself and not the instance of the browser which Selenium is controlling. – esqew Jan 24 '22 at 15:11
  • You could send an enter key outside of selenium, I agree with you that this is not the best solution, and more of a patch. – Aron Atilla Hegedus Jan 24 '22 at 15:17