如何为 gecko 驱动程序设置特定配置文件

问题描述 投票:0回答:1

在这段代码中,我认为只有 --headless 可以正常工作
我尝试使用 -p 或 --profile “firefox 配置文件的路径”,但这些都不起作用

def initialize_web_driver():
    try:
        firefox_options = webdriver.FirefoxOptions()
        firefox_options.add_argument('--headless')
        firefox_options.add_argument("-p GPTT")
        firefox_options.set_preference("browser.shell.checkDefaultBrowser", False)              
        driver = webdriver.Firefox(options=firefox_options)
        driver.set_window_size(1920, 1080)
        return driver
    except Exception as e:
        print(f"Error initializing WebDriver: {str(e)}")
        return None
python selenium-webdriver geckodriver
1个回答
0
投票

尝试

fp = webdriver.FirefoxProfile('/path/to/profile')

FirefoxProfile profile = new FirefoxProfile(new File("path/to/profile"));
FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);
capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
© www.soinside.com 2019 - 2024. All rights reserved.