无法使用Selenium在Windows 7中启动Chrome无头浏览器

时间:2017-08-14 09:46:42

标签: selenium-chromedriver google-chrome-headless

 **Sinppet**  

 if (os.contains("win")) {
                    System.out.println("OS: WINDOWS");  
                    System.setProperty("webdriver.chrome.driver", localPath+"chromedriver.exe");
                    ChromeOptions chromeOptions = new ChromeOptions();
                    chromeOptions.addArguments("headless");
                    return new ChromeDriver(chromeOptions);
                } else if (os.contains("mac")) {
                    System.out.println("OS: MAC");              
                    System.setProperty("webdriver.chrome.driver", localPath+"chromedriver_mac64");
                    return new ChromeDriver();
                }

我正面临的错误

org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.xpath: //input[@id='user_id'] (tried for 180 second(s) with 500 MILLISECONDS interval)
    at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:232)
    at com.adp.marketplace.frwk.selenium.SeleniumFunctions.waitForVisibilityByXpath(SeleniumFunctions.java:510)
    at com.adp.marketplace.prm.SSOTestInPRMSteps.The_user_logged_into_PRM_with_valid_cred(SSOTestInPRMSteps.java:28)
    at ?.Given the user logged into PRM with valid creds(com/adp/marketplace/prm/SSOTestsInPRM.feature:7)

1 个答案:

答案 0 :(得分:3)

无头的论点是错误的,应该是:

chromeOptions.addArguments("--headless");

使用 - 在无头之前,就像你从快捷方式添加参数一样: enter image description here

相关问题