无头模式会出现错误,而非无头模式则不会出现错误

问题描述 投票:0回答:1

我在无头模式下运行我的脚本,并且遇到了在非无头模式下运行相同脚本时不会发生的错误。 “ExpectedConditions”行持续点击“预期条件失败:等待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

任何想法我做错了什么?

selenium wait headless
1个回答
0
投票

这是Chrome的无头模式代码

        case "chromeheadless":
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.addArguments("--headless");
            chromeOptions.addArguments("window-size=1440,900");
            driver.set(new ChromeDriver(chromeOptions));
            break;
© www.soinside.com 2019 - 2024. All rights reserved.