首页 > 解决方案 > 当有 2 个日期字段时,不会使用 WebDriverWait 处理 org.openqa.selenium.ElementNotVisibleException。如何解决?[不重复]

问题描述

我正在尝试自动化网页中的 2 个日期字段,“开始日期”和“结束日期”。但是在单击“结束日期”之前,我得到了 org.openqa.selenium.ElementNotVisibleException 异常。

HTML:

开始日期:

<td role="gridcell" id="ext-gen3261" title="May 01, 2019" class="x-datepicker-active x-datepicker-cell x-datepicker-selected">
<a role="presentation" hidefocus="on" class="x-datepicker-date" href="#">1</a>
</td>

结束日期:

<td role="gridcell" id="ext-gen3310" title="May 02, 2019" class="x-datepicker-active x-datepicker-cell">
<a role="presentation" hidefocus="on" class="x-datepicker-date" href="#">2</a>
</td>

我可以将 WebDriverWait 用于“结束日期”字段,并在选择“开始日期”时克服该问题不是自动的。(仅当“结束日期”是自动的)。

        driver.findElement(By.id("ext-gen3220")).click(); //id of the calendar icon = 'ext-gen3220'
        WebDriverWait wait2 = new WebDriverWait(driver,30);
        wait2.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//td[@title='May 02, 2019']")));  
        driver.findElement(By.xpath("//td[@title='May 02, 2019']")).click();

(考试通过了)

但是,当我自动选择开始日期和结束日期时,此解决方案不起作用。

        driver.findElement(By.id("ext-gen3218")).click(); //id of the start date calendar icon = 'ext-gen3218'
        WebDriverWait wait1 = new WebDriverWait(driver, 30);
        wait1.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//td[@title='May 01, 2019']")));
        driver.findElement(By.xpath("//td[@title='May 01, 2019']")).click();


        driver.findElement(By.id("ext-gen3220")).click();  //id of the end date calendar icon = 'ext-gen3220'
        WebDriverWait wait2 = new WebDriverWait(driver,30);
        wait2.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//td[@title='May 02, 2019']")));  
        driver.findElement(By.xpath("//td[@title='May 02, 2019']")).click();

我再次得到 org.openqa.selenium.ElementNotVisibleException 异常。

如何解决仅在自动化两个日期字段时出现的问题?

标签: javaeclipseseleniumselenium-webdriverautomated-tests

解决方案


推荐阅读