首页 > 解决方案 > Microsoft Edge WebDriver - 无法为自动化使用默认应用数据配置文件 - Edge Ver 80

问题描述

我必须使用现有的用户登录会话,我们将需要 EDGE 用户配置文件,因为我们观察到 EDGE 驱动程序不使用现有的用户数据配置文件,它每次都会创建一个新的配置文件

EDGE 默认配置文件路径

C:\Users\edge2automation\AppData\Local\Microsoft\Edge\User Data\Default

(边缘驱动程序)路径 -

C:\Users\edge2automation\AppData\Local\Temp\scoped_dir64860_1277252271\Default

标签: seleniumautomationmicrosoft-edgeselenium-edgedriver

解决方案


由于新的Edge是基于Chromium的,我们可以参考使用Chrome profile的解决方案,将关键词改为Edge:

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.edge.EdgeDriver; 
import org.openqa.selenium.edge.EdgeOptions;


public class Edgeauto {
    public static void main(String[] args) { 
        System.setProperty("webdriver.edge.driver", "your\\path\\to\\edge\\webdriver\\msedgedriver.exe"); 
        EdgeOptions edgeOptions = new EdgeOptions();
        edgeOptions.addArguments("user-data-dir=C:\\Users\\edge2automation\\AppData\\Local\\Microsoft\\Edge\\User Data");
        edgeOptions.addArguments("--start-maximized");
        WebDriver driver = new EdgeDriver(edgeOptions); 
        driver.get("https://www.google.com/");
    }
}

请注意,这需要使用 selenium-server-4.0.0-alpha-4,您可以在此处下载表格。


推荐阅读