Python Selenium - How to configure a client certificate file while initializing PhantomJS driver instance
Python Selenium - How to configure a client certificate file while initializing PhantomJS driver instance
I need to use a certificate .cer to connect to a website. I use PhantomJS with Python. This is the connection code: driver webdriver.PhantomJSexecutable_pathSeleniumbinphantomjs, service_args--ssl-client-certificate-filecertificate.cer, desired_capabilitiesdcap However, the HTML returned is: htmlheadheadbodybodyhtml and the URL is: about:blank But if I remove: --ssl-client-certificate-filecertificate.cer Then I get the correct URL and some HTML content forbidden message because the certificate is missing. Any idea what I can do to solve this issue UPDATE 1 Ghostdriver.log contains the following: INFO - 2018-04-27T15:18:44.680Z GhostDriver - Main - running on port 55768 INFO - 2018-04-27T15:18:44.960Z Session 46addab0-4a2e-11e8-879b-bb8782c84ba6 - page.settings - XSSAuditingEnabled:false,javascriptCanCloseWindows:true,javascriptCanOpenWindows:true,javascriptEnabled:true,loadImages:true,localToRemoteUrlAccessEnabled:false,userAgent:Mozilla5.0 Macintosh; Intel Mac OS X AppleWebKit538.1 KHTML, like Gecko PhantomJS2.1.1 Safari538.1,webSecurityEnabled:true INFO - 2018-04-27T15:18:44.960Z Session 46addab0-4a2e-11e8-879b-bb8782c84ba6 - page.customHeaders: - INFO - 2018-04-27T15:18:44.960Z Session 46addab0-4a2e-11e8-879b-bb8782c84ba6 - Session.negotiatedCapabilities - browserName:phantomjs,version:2.1.1,driverName:ghostdriver,driverVersion:1.2.0,platform:mac-unknown-64bit,javascriptEnabled:true,takesScreenshot:true,handlesAlerts:false,databaseEnabled:false,locationContextEnabled:false,applicationCacheEnabled:false,browserConnectionEnabled:false,cssSelectorsEnabled:true,webStorageEnabled:false,rotatable:false,acceptSslCerts:false,nativeEvents:true,proxy:proxyType:direct,phantomjs.page.settings.javascriptEnabled:true INFO - 2018-04-27T15:18:44.960Z SessionManagerReqHand - _postNewSessionCommand - New Session Created: 46addab0-4a2e-11e8-879b-bb8782c84ba6 INFO - 2018-04-27T15:19:26.438Z SessionManagerReqHand - _cleanupWindowlessSessions - Asynchronous Sessions clean-up phase starting NOW UPDATE 2 - using logging.getLogger 2018-04-30 09:39:56,730 - selenium.webdriver.remote.remote_connection - DEBUG - POST http:127.0.0.1:57672wdhubsession requiredCapabilities: , desiredCapabilities: platform: ANY, browserName: phantomjs, version: , phantomjs.page.settings.javascriptEnabled: true, javascriptEnabled: true 2018-04-30 09:39:56,745 - selenium.webdriver.remote.remote_connection - DEBUG - Finished Request 2018-04-30 09:39:56,745 - selenium.webdriver.remote.remote_connection - DEBUG - POST http:127.0.0.1:57672wdhubsession0f971930-4c52-11e8-8957-cd8a79dc644curl url: https:idp.iamfas.belgium.befasuilogincommercialnoidservice, sessionId: 0f971930-4c52-11e8-8957-cd8a79dc644c 2018-04-30 09:39:56,971 - selenium.webdriver.remote.remote_connection - DEBUG - Finished Request 2018-04-30 09:39:56,971 - selenium.webdriver.remote.remote_connection - DEBUG - GET http:127.0.0.1:57672wdhubsession0f971930-4c52-11e8-8957-cd8a79dc644csource sessionId: 0f971930-4c52-11e8-8957-cd8a79dc644c 2018-04-30 09:39:56,974 - selenium.webdriver.remote.remote_connection - DEBUG - Finished Request HTML FOUND: htmlheadheadbodybodyhtml 2018-04-30 09:39:56,974 - selenium.webdriver.remote.remote_connection - DEBUG - GET http:127.0.0.1:57672wdhubsession0f971930-4c52-11e8-8957-cd8a79dc644curl sessionId: 0f971930-4c52-11e8-8957-cd8a79dc644c 2018-04-30 09:39:56,980 - selenium.webdriver.remote.remote_connection - DEBUG - Finished Request URL: about:blank 2018-04-30 09:39:56,980 - selenium.webdriver.remote.remote_connection - DEBUG - POST http:127.0.0.1:57672wdhubsession0f971930-4c52-11e8-8957-cd8a79dc644celement using: id, sessionId: 0f971930-4c52-11e8-8957-cd8a79dc644c, value: proceedButton 2018-04-30 09:39:57,278 - selenium.webdriver.remote.remote_connection - DEBUG - Finished Request
To use a certificate .cer while connecting to a website through PhantomJS and Python you need to provide the absolute path of the --ssl-client-certificate-file e.g. C:pathtocertificate.cer as a service_argsand you can use the following line of code : driver webdriver.PhantomJSexecutable_pathSeleniumbinphantomjs, service_args--ssl-client-certificate-fileC:pathtocertificate.cer, desired_capabilitiesdcap
Комментарии
Отправить комментарий