【问题标题】:selenium load chrome profile java硒加载铬配置文件java
【发布时间】:2020-05-02 07:33:41
【问题描述】:

我尝试使用 selenium 加载 chrome 配置文件。但是,每当我上传个人资料时,都会出现错误:

invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use - user-data-dir.
String chromeProfile = "C:\\Users\\ad\\AppData\\Local\\Google\\Chrome\\User Data";
ChromeDriverService chSvc = new ChromeDriverService.Builder()
   .usingDriverExecutable(new File("C:\\Driver\\chromedriver.exe")).usingAnyFreePort().build();
ChromeOptions chOption = new ChromeOptions();
chOption.addArguments("--user-data-dir=" + chromeProfile);
chOption.addArguments("--profile-directory=Profile 33");
chOption.addArguments("--start-maximized");        
ChromeDriver driver = new ChromeDriver(chSvc, chOption);
driver.get("https://google.com");

【问题讨论】:

    标签: java selenium profile


    【解决方案1】:

    您不能使用相同的user-data-dir 运行多个 ChromeDriver 实例。您可以做的是每次创建 ChromeDriver 实例时,创建一个临时目录,然后在 ChromeOptions 中设置它chOption.addArguments("--user-data-dir=" + tempDir);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-01
      • 2021-11-14
      • 1970-01-01
      • 2016-12-17
      • 1970-01-01
      • 2017-09-02
      • 1970-01-01
      • 2022-10-23
      相关资源
      最近更新 更多