无头模式遇到错误,而无头模式则没有

时间:2019-02-15 22:46:44

标签: selenium wait headless

我正在以无头模式运行脚本,并且遇到了在非无头模式下运行相同脚本时不会发生的错误。 “ ExpectedConditions”行继续命中“ Expected condition failed:等待由By.xpath定位的元素的可见性:// div [@ id ='sidebar-top-item'](尝试进行了10秒钟(500毫秒)间隔)“错误

@Test (priority=2)
public void ChangePassword() {

    // Wait for Dashboard Button
    WebDriverWait wait = new WebDriverWait(driver, 15);
    WebElement dashButton = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(text(),'Go To Dashboard')]")));
    dashButton.click();

    // Change Password
    WebElement proNameX = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@id='sidebar-top-item']")));
    proNameX.click();
    WebElement changePass = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='nf-change-password-btn']")));
    changePass.click();

    //driver.findElement(By.xpath("//div[@id='nf-change-password-btn']")).click();
    driver.findElement(By.name("old_password")).sendKeys("Password");
    driver.findElement(By.name("new_password")).sendKeys("NewPassword");
    driver.findElement(By.name("new_password2")).sendKeys("NewPassword");
    driver.findElement(By.xpath("//button[@type='button']")).click();
    log.info("Password Change Completed");

Dom

有任何想法我在做什么错吗?

1 个答案:

答案 0 :(得分:0)

这是我的Chrome浏览器无头模式代码

        case "chromeheadless":
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.addArguments("--headless");
            chromeOptions.addArguments("window-size=1440,900");
            driver.set(new ChromeDriver(chromeOptions));
            break;