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

如何使用selenium webDriver打开具有特定配置文件的MS Edge?,selenium,webdriver,microsoft-edge,Selenium,Webdriver,Microsoft Edge,我正在边缘浏览器上运行自动化。边缘浏览器支持配置文件,每当我从webdriver启动边缘时,它都会创建新的配置文件。有什么方法可以设置使用给定用户配置文件启动edge的选项吗?我使用Java语言作为示例。您可以使用user data dir和profile directory来使用特定的概要文件来启动带有Selenium的Edge。示例代码如下所示: System.setProperty("webdriver.edge.driver", "your\\path\\to\\edge\\webdri

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

我使用Java语言作为示例。您可以使用user data dir和profile 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/ 如下图所示:

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");