java - Selenium ChromeDriver 不会使用默认用户数据来访问 url

标签 java google-chrome selenium selenium-webdriver selenium-chromedriver

它会在一个带有默认开始菜单的新窗口中打开,并显示一条通知,表明 Chrome 正在受到自动化测试软件的控制,但它不会转到该网址。

System.setProperty("webdriver.chrome.driver","C:\\Users\\"+System.getProperty("user.name")+"\\chromedriver.exe");

    ChromeOptions options = new ChromeOptions();
    options.setBinary("C:\\Users\\"+System.getProperty("user.name")+"\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");
    options.addArguments("--user-data-dir=C:\\Users\\"+System.getProperty("user.name")+"\\AppData\\Local\\Google\\Chrome\\User Data\\");
    WebDriver driver = new ChromeDriver(options);
    driver.get("https://www.google.com");

我也尝试过:

        System.setProperty("webdriver.chrome.driver","C:\\Users\\"+System.getProperty("user.name")+"\\chromedriver.exe");

    ChromeOptions options = new ChromeOptions();
    options.setBinary("C:\\Users\\"+System.getProperty("user.name")+"\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");
    options.addArguments("--user-data-dir=C:\\Users\\"+System.getProperty("user.name")+"\\AppData\\Local\\Google\\Chrome\\User Data\\");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    WebDriver driver = new ChromeDriver(capabilities);
    driver.get("https://www.google.com");

它给出的异常(exception)

Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: crashed (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 61.65 seconds

我使用的是最新的 ChromeDriver 2.30 和 Selenium 3.4.0 版本

最佳答案

找到了我自己问题的答案。当我从配置文件路径复制默认文件夹并将其移至其他位置时,它起作用了。

    ChromeOptions options = new ChromeOptions();
    options.addArguments("user-data-dir=C:/Users/"+System.getProperty("user.name")+"/Desktop/");
    options.addArguments("--start-maximized");
    WebDriver driver = new ChromeDriver(options);
    driver.get("https://www.google.com");

关于java - Selenium ChromeDriver 不会使用默认用户数据来访问 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44875582/

相关文章:

java - 线程中的异常 "main"java.lang.NoSuchMethodError : io. appium.java_client.TouchAction.longPress(Lorg/openqa/selenium/WebElement;)

java - 已订购 SQlite 数据库(基于 XML feed)

java - UnityPlayerActivity全局初始化

google-chrome - 远程调试——如何创建端口代理?

css - chrome 中的打印(另存为 pdf)问题

javascript - Google Chrome 上的 Ext JS Grid 主体宽度问题

java - Android 锁屏事件?

java - Android水平 ScrollView

java - 使用 Selenium(Java),当下拉列表元素的可识别属性有限时,如何从下拉列表中选择一个值?

javascript - 总结许多连续 if(x typeof != ='unedfined' ) 查询的最佳方法?