Use browser client certificate with Selenium and PhantomJS
Use PFX client certificates files in Phantomjs and Selenium web automation tools. I want to get up and running a web bot that have to connect to a website via a client certificate.
The only i can find is PhantomJS (i know it’s discontinued for now, but it just works).
So after long trials and errors i came up with this.
I have a PFX certificate file, password protected. So i have to split the certificate in two different keys, the key file and the client one; with openssl, removing the password protection also (see the Openssl man for more info).
And now we can use Selenium with client certificate!
from os.path import expanduser import selenium d = selenium.webdriver.phantomjs.webdriver.WebDriver(service_args=[ "--ssl-client-certificate-file="+client_pem_file.path, "--ssl-client-key-file="+key_pem_file.path, ]) d.implicitly_wait(30) d.get('https://yourcertificatedomain.com') home = expanduser("~") d.save_screenshot(home + '/screenshot.png')