org.openqa.selenium.InvalidArgumentException:无效参数

时间:2019-10-04 19:42:33

标签: selenium selenium-chromedriver

我是这个网站的新手,我想请您提供有关此问题的帮助和专家意见。

我目前正在尝试使用Netbeans和Selenium运行简单的代码,但是每次运行代码时,都会出现错误“线程“ main”中的异常” org.openqa.selenium.InvalidArgumentException:无效参数:user数据目录已在使用中,请为--user-data-dir参数指定一个唯一值,或者不要使用--user-data-dir“

这是我要运行的代码,奇怪的是我可以在另一台计算机上成功运行相同的代码。

package selenium.test;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class SeleniumTest {

private static WebDriver driver = null;

public static void main(String[] args) {

    System.setProperty("webdriver.chrome.driver",
            "C:\\Users\\Kevin\\Documents\\Selenium\\Driver\\chromedriver.exe");

driver = new ChromeDriver();
driver.get ("https:\\www.google.com");
}
}

Chrome版本:77.0.3865.90

ChromeDriver版本:77.0.3865.40

Netbeans:8.2

非常感谢您的帮助

1 个答案:

答案 0 :(得分:0)

使用ChromeOptions。您可以指定一个目录,而不是您的用户目录:

    ChromeOptions co = new ChromeOptions();
    co.addArguments("user-data-dir=C:\\Some\\valid\\data dir\\");