[英]How can I set up Selenium to use multiple Firefox profiles?
I am using selenium and want to use separate firefox profiles for 3 different scripts. 我正在使用selenium并希望为3种不同的脚本使用单独的firefox配置文件。 Is this possible? 这可能吗?
Not sure how you are executing your scripts, but when you instantiate your webdriver
object, you can specify a FirefoxProfile
as the firefox_profile
argument. 不确定如何执行脚本,但是当您实例化webdriver
对象时,可以将FirefoxProfile
指定为firefox_profile
参数。 This is done by creating a FirefoxProfile
object (example below) and providing the path to your target profile as the argument: 这是通过创建FirefoxProfile
对象(下面的示例)并提供目标配置文件的路径作为参数来完成的:
from selenium import webdriver
# ...
profile = webdriver.firefox.firefox_profile.FirefoxProfile('/path/to/your/profile')
driver = webdriver.Firefox(firefox_profile=profile)
To the best of my knowledge you can't modify the profile after the driver
has been instantiated (I could be wrong about this though - worth experimenting if that is what you need to do :) ). 据我所知,在实例化driver
后你无法修改配置文件(虽然我可能错了 - 值得尝试,如果这是你需要做的:))。 That being the case, in each of your scripts you would create a profile that pointed to the profile you want to use, and then instantiate the driver
with the firefox_profile
argument pointed to the profile
object created by FirefoxProfile
. 在这种情况下,您可以在每个脚本中创建一个指向您要使用的配置文件的配置文件,然后使用指向FirefoxProfile
创建的profile
对象的firefox_profile
参数来实例化driver
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.