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

最后都变了- 提交于 2021-02-11 12:32:23

问题


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 ?


回答1:


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.

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



来源:https://stackoverflow.com/questions/62242103/how-to-open-ms-edge-with-specific-profile-with-selenium-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!