【发布时间】:2016-10-14 20:39:51
【问题描述】:
元素的“禁用”属性仅在启用按钮时出现。对于禁用状态,属性 disabled="disabled" 不会显示在 HTMl 中(属性本身而不是值)
如何检查属性,如果不存在则继续
我试过了
driver.findElement(By.id("button")).getAttribute("disabled") != "disabled"
但是当按钮处于禁用状态时,此行会失败,因为没有“禁用”属性
HTML
<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">
【问题讨论】:
-
正如您所说的,当启用了“id= button”的按钮时,属性 disabled 存在。当按钮被禁用时,属性 disabled 不存在。那么你到底想要达到什么目的?请简化您的问题并为其添加更多 HTML 代码 sn-p。
-
如果你尝试了 driver.findElement(By.id("button")).getAttribute("disabled") != null .
-
当我使用上面的内容时,我没有收到错误,但是 While 退出而不读取页面的详细信息。所以 Do While 循环并不能解决问题。无论如何,如果你以上回答我可以将您的答案设置为已接受