以下方法无法正常工作。由于使用了 GRID,因此这里将能力设置为空。
System.setProperty("webdriver.chrome.driver", "C:/chromedriver.exe");
DesiredCapabilities capability=null;
方法一:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--user-data-dir=C:/Users /username/AppData/Local/Google/Chrome/User Data/Default"));
driver = new ChromeDriver(capabilities);
方法二:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
String chromeProfile = "C:/Users/username/AppData/Local/Google/Chrome/Application /chrome.exe";
ArrayList<String> switches = new ArrayList<String>();
switches.add("C:/Users/username/AppData/Local/Google/Chrome/User Data/Default" + chromeProfile);
capabilities.setCapability("chrome.switches", switches);
driver = new ChromeDriver(capabilities);