java - 当有 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 异常。
如何解决仅在自动化两个日期字段时出现的问题?
解决方案
推荐阅读
- python - 有没有办法将神经网络层中的每个节点乘以特定值?(凯拉斯)
- c++ - Visual Studio 2019 map::operator[] 中的非合法优化?
- javascript - 更改字段条件的工具提示图标
- python - 从数据帧绘制的两条曲线之间的交点和返回点
- node.js - 如何在 $beforeUpdate 挂钩中获取整个 ObjectionJS 对象?
- excel - 如何使用 VBA 自动单击公司安全弹出窗口上的“发送”按钮
- reactjs - 使用 IIS API 实现 react redux
- java - 从 firebase 检索数据到 recyclerview
- json - FLUTTER : 将 Json 对象转换为模型
- yaml - 管道 - 如果至少一个先前的作业成功,则运行一个作业