如何检查元素的禁用状态,然后在 selenium webdriver 中继续 [英] How to check for disabled state of element and then continue in selenium webdriver

查看:31
本文介绍了如何检查元素的禁用状态,然后在 selenium webdriver 中继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个按钮,脚本一直点击按钮直到它到达最后一页.它应该读取和比较每个页面中的数据,然后一旦按钮被禁用,它应该退出循环.当下一个按钮处于启用状态时,它会读取数据并进行比较而不会出现问题,但是当下一个按钮被禁用时,脚本不会读取该页面

I have this next button and the script keeps clicking the button until it gets to the last page. It should read and compare data in each page and then it should exit from the loop once the button is disabled. It reads data and does the comparison without problems when next button is in an enabled state, but when the next button is disabled the script doesn't read that page

这是元素

这是我的代码

do {
....
....

      if(driver.findElement(By.id("ReportViewer1_ctl06_ctl00_Next_ctl00_ctl00")).isDisplayed()) {

      driver.findElement(By.id("ReportViewer1_ctl06_ctl00_Next_ctl00_ctl00")).click();

        } else {

        }           
   } while(driver.findElement(By.id("ReportViewer1_ctl06_ctl00_Next_ctl00_ctl00")).isDisplayed());

问题是当到达第二页时,next 按钮被禁用,While 退出而不读取第 2 页中的数据.

The problem is that when the second page is reached, next the button becomes disabled and the While exits without reading the data in page 2.

如何确保页面被阅读

  1. 当只有一页数据时(所以下一步按钮将在开始时被禁用)

  1. When there is only 1 page of data(so next button will be disabled at the start itself)

到达最后一页时,(下一个按钮进入禁用状态)

When the last page is reached, (the next button goes to disabled state)

我尝试过 FluentWait 但失败了,如这里所述 https://stackoverflow.com/questions/29282178/selenium-fluentwait-method-failing-to-ignore-nosuchelement

I had tried FluentWait but failed as described here https://stackoverflow.com/questions/29282178/selenium-fluentwait-method-failing-to-ignore-nosuchelement

EDIT..为按钮的禁用状态添加了HTML

EDIT..added the HTML for disabled state of button

<td>
    <input id="ReportViewer1_ctl06_ctl00_Next_ctl01_ctl00" type="image" 
style="border-style: none; height: 16px; width: 16px; border-width: 0px; cursor: default;"
 alt="Next Page" src="/xxxx Reserved.ReportViewerWebControl.axd?OpType=Resource&Version=
0.0.30319.1&Name=Microsoft.Reporting.WebForms.Icons.NextPageDisabled.gif" 
title="Next Page" disabled="disabled" name="ReportViewer1$ctl06$ctl00$Next$ctl01$ctl00">

再次编辑---启用按钮时的 HTML(没有禁用属性)

EDIT again --- The HTML when the button is enabled(There is no disabled attribute)

<input id="ReportViewer1_ctl06_ctl00_Next_ctl00_ctl00" type="image" style="border-style: 
none; height: 16px; width: 16px; border-width: 0px;" alt="Next Page" 
src="/xxxxx/Reserved.ReportViewerWebControl.axd?OpType=Resource&Version=10.0.30319.
1&Name=Microsoft.Reporting.WebForms.Icons.NextPage.gif"
 title="Next Page" name="ReportViewer1$ctl06$ctl00$Next$ctl00$ctl00">

推荐答案

您需要使用 isEnabled() 检查而不是 isDisplayed().

这篇关于如何检查元素的禁用状态,然后在 selenium webdriver 中继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆