如何使用 selenium webDriver 打开具有特定配置文件的 MS Edge? [英] How to open MS Edge with specific profile with selenium webDriver?

查看:99
本文介绍了如何使用 selenium webDriver 打开具有特定配置文件的 MS Edge?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am running automation on the edge browser. Edge browser supports profile and whenever i launch the edge from webdriver, it create new profile. Is there any way I can set the option to launch edge with given user profile ?

推荐答案

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

I use Java language as an example. You could use user-data-dir and profile-directory to use specific profile to launch Edge with Selenium. The sample code is like below:

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

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

Note: Change the paths in the code to your owns.

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

If you don't know the path of the specific profile, you could check edge://version/ like below:

这篇关于如何使用 selenium webDriver 打开具有特定配置文件的 MS Edge?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆