Python和Selenium:如何多次更改Firefox的配置文件 [英] Python and selenium: how to change Firefox's profile multiple times

查看:73
本文介绍了Python和Selenium:如何多次更改Firefox的配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了Firefox的配置文件并使用该配置文件启动了驱动程序,之后,我想知道如何多次更改该配置文件的某些首选项,或者如何在启动驱动程序后更改配置文件?这是我用于设置个人资料的代码:

I set up Firefox's profile and launched the driver with that profile, after that, I want to know how to change some preferences on that profile multiple times, or how to change the profile after launching the driver? here is my code for setting up the profile:

profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.helperApps.alwaysAsk.force', False)
profile.set_preference('browser.download.dir', 'D:\\Workspace\\Res')
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', "application/x-7z-compressed")


driver = webdriver.Firefox(profile, executable_path=r"C:\geckodriver\geckodriver.exe")

推荐答案

按照具有所需的 Options Capabilities 的WebDriver 实例,并将 Web浏览器会话初始化为打开浏览上下文,您将无法更改功能运行时.即使您能够检索运行时功能,也仍然无法将其改回.

As per the current implementation of Selenium once you configure the WebDriver instance with the required Options and Capabilities and initialize the Web Browser session to open a Browsing Context, you cannot change the capabilities runtime. Even if you are able to retrieve the runtime capabilities still you won't be able to change them back.

因此,为了更改 用户个人资料,您必须启动一个新的 WebDriver 会话.

So, in-order to change the firefox User Profile you have to initiate a new WebDriver session.

这里是@JimEvans 清晰简洁的评论(截至13年10月24日,13:02)与代理设置功能有关:

Here is @JimEvans clear and concise comment (as of Oct 24 '13 at 13:02) related to proxy settings capability:

为任何给定的驱动程序设置代理时,仅在创建WebDriver会话时才进行设置;它不能在运行时更改.即使您具有创建的会话的功能,也将无法更改它.因此答案是,不,如果要使用其他代理设置,则必须开始新的会话.

When you set a proxy for any given driver, it is set only at the time WebDriver session is created; it cannot be changed at runtime. Even if you get the capabilities of the created session, you won't be able to change it. So the answer is, no, you must start a new session if you want to use different proxy settings.


Outro

您可以在 查看全文

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