如何使用 selenium webDriver 打开具有特定配置文件的 MS Edge?

How to open MS Edge with specific profile with selenium webDriver?

我在边缘浏览器上运行自动化。 Edge 浏览器支持配置文件,每当我从 webdriver 启动 edge 时,它​​都会创建新的配置文件。有什么方法可以设置选项以使用给定的用户配置文件启动边缘?

我以Java语言为例。您可以使用 user-data-dirprofile-directory 来使用特定的配置文件来启动带有 Selenium 的 Edge。示例代码如下:

System.setProperty("webdriver.edge.driver", "your\path\to\edge\webdriver\msedgedriver.exe"); 
EdgeOptions edgeOptions = new EdgeOptions();

// Here you set the path of the profile ending with User Data not the profile folder
edgeOptions.addArguments("user-data-dir=C:\Users\username\AppData\Local\Microsoft\Edge\User Data");

// Here you specify the actual profile folder
edgeOptions.addArguments("profile-directory=Profile 2");

edgeOptions.addArguments("--start-maximized");
WebDriver driver = new EdgeDriver(edgeOptions); 
driver.get("https://www.google.com");

注意:将代码中的路径更改为您自己的。

如果您不知道具体配置文件的路径,您可以检查edge://version/,如下所示: