Selenium-如何从现有的Firefox配置文件中导入所有设置 [英] Selenium - How to import all settings from an existing Firefox profile

查看:91
本文介绍了Selenium-如何从现有的Firefox配置文件中导入所有设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为什么要这样做:

我需要使需要客户端SSL证书的网站自动化.我知道这是无法使用fp.set_preference()指定的选项.我无法控制要连接的服务器,因此无法更改安全设置.

I need to automate a website that requires client-side SSL certificates. I understand this to be an option which cannot be specified using fp.set_preference(). I am not in control of the server I am connecting to thus I cannot change the security setup.

我尝试了什么

我创建了一个单独的Firefox配置文件,其中设置了必需的受客户端密码保护的SSL证书",并自动选择一个证书和一些手动代理设置(SOCKS 5).经过大量谷歌搜索后,我将代码设置如下:

I have created a separate Firefox profile which has the required 'client-side password protected SSL certificates' set up, select one certificate automaticaly and some manual proxy settings (SOCKS 5). After much googling I have set my code as follows:

from selenium import webdriver
url = 'https://www.paininneck.co.uk'
fp = webdriver.FirefoxProfile(r"""C:\Users\
<user>\AppData\Local\Mozilla\Firefox\Profiles\<Firefox>""")
driver = webdriver.Firefox(fp)
driver.get(url)

问题:

浏览器确实打开,但是,它仍在使用默认配置文件.我在其他配置文件中更改的设置均未复制.我的代码中指定的配置文件仍可以通过Firefox UI进行选择.

The browser does open, however, it is still using the default profile. None of the settings I have changed in the other profile has copied across. The profile specified in my code is still working with selecting it through the Firefox UI.

我希望我错过了一些简单的事情,而且一直以来谷歌搜索一直没有白费!我不愿意更改为默认设置,但是在调整了默认配置文件以查看设置是否可以复制之后,很明显它们没有,并且Selenium每次都进行了干净的复制.

I am hoping I missed something simple and all this time googling has not been in vain! I am reluctant to change to default settings, however after tweaking the default profile to see if the settings would copy over it is apparent that they don't and Selenium is making a clean copy each time.

亲切的问候

丰富

版本:

Python==3.6.1,
Selenium==3.4.3,
Firefox==53
gecko driver==v0.16.1
OS==Windows(Its for work dont judge me!)

推荐答案

使用Selenium 3.4.x,Python 3.6.1和geckodriver v0.16.1&在Mozilla Firefox 53.0中,您可以通过以下步骤使用现有的Firefox配置文件:

Using Selenium 3.4.x, Python 3.6.1 along with geckodriver v0.16.1 & Mozilla Firefox 53.0, you can use the existing Firefox profile through the following steps:

  1. 在Windows框中找到Firefox配置文件目录.例如我的Firefox配置文件"debanjan"位于C:\\Users\\AtechM_03\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles,名称为w8iy627a.debanjan.
  2. 接下来,启动webdriver时必须指定Firefox Profile目录的绝对路径.
  3. 这是在我的Windows计算机上打开现有Firefox配置文件'debanjan'的工作代码:

  1. Locate the Firefox Profile directory on your windows box. For e.g. my Firefox Profile "debanjan" was located at C:\\Users\\AtechM_03\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles by the name w8iy627a.debanjan.
  2. Next, you have to specify the absolute path of the Firefox Profile directory when you initiate the webdriver.
  3. Here is the working code which opens an existing Firefox Profile 'debanjan' on my Windows machine:

要注意的是,当前的Selenium-Python绑定对于geckodriver来说是不稳定的,并且看起来是特定于体系结构的.您可以找到github 讨论

It is to be noted that the current Selenium-Python binding is unstable with geckodriver and looks to be Architecture specific. You can find the github discussion and merge here. So you may additionally need to pass the absolute path of the firefox binary while initializing the webdriver

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

profile = webdriver.FirefoxProfile('C:\\Users\\AtechM_03\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\w8iy627a.debanjan')
binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe')

driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
url = 'https://www.paininneck.co.uk'
driver.get(url)

这篇关于Selenium-如何从现有的Firefox配置文件中导入所有设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆