当您使用 Selenium 启动 Web 驱动程序时,它会打开相应 Web 浏览器的一个新实例(看起来好像刚刚安装,没有历史记录和默认设置}。
有什么方法可以打开通常的窗口,这些窗口将具有我在 chrome 或 Firefox 中完成的自定义设置,例如附加组件和所有设置?
最佳答案
您可以在 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);
关于java - 使用 Selenium Webdriver 时如何打开通常的 chrome 或 Firefox 窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28340353/