Search code examples
pythongoogle-chromewebautomation

Web automation: login with certificate Chrome Python


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!


Solution

  • 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