【发布时间】:2023-12-30 21:38:01
【问题描述】:
当您使用 Selenium 启动 Web 驱动程序时,它会打开一个新的、非常新鲜的相应 Web 浏览器实例(看起来好像刚刚安装,没有历史记录和默认设置)。
有什么方法可以打开通常的窗口,这些窗口将具有我在我的 chrome 或 Firefox 中完成的自定义设置,如附加组件和所有?
【问题讨论】:
标签: java c# selenium selenium-webdriver
当您使用 Selenium 启动 Web 驱动程序时,它会打开一个新的、非常新鲜的相应 Web 浏览器实例(看起来好像刚刚安装,没有历史记录和默认设置)。
有什么方法可以打开通常的窗口,这些窗口将具有我在我的 chrome 或 Firefox 中完成的自定义设置,如附加组件和所有?
【问题讨论】:
标签: java c# selenium selenium-webdriver
您可以在 FireFox 中使用现有配置文件
File profileDir = new File("Path to default profile")
FirefoxProfile firefoxProfile = new FirefoxProfile(profileDir);
WebDriver webDriver = new FirefoxDriver(firefoxProfile);
对于 Chrome,您可以使用以下选项:
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data");
driver = new ChromeDriver(options);
【讨论】: