【问题标题】:How to open MS Edge with specific profile with selenium webDriver?如何使用 selenium webDriver 打开具有特定配置文件的 MS Edge?
【发布时间】:2020-06-07 07:20:57
【问题描述】:

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

【问题讨论】:

    标签: selenium webdriver microsoft-edge


    【解决方案1】:

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

    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/,如下所示:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-24
      • 1970-01-01
      • 1970-01-01
      • 2020-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多