How can I set up Selenium to use multiple Firefox profiles?

前端 未结 1 1791
小鲜肉
小鲜肉 2021-01-25 12:34

I am using selenium and want to use separate firefox profiles for 3 different scripts. Is this possible?

相关标签:
1条回答
  • 2021-01-25 12:52

    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. This is done by creating a FirefoxProfile object (example below) and providing the path to your target profile as the argument:

    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 :) ). 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.

    0 讨论(0)
提交回复
热议问题