Selenium Webdriver C# element.Enabled evaluating to true when element is still disabled

旧巷老猫 提交于 2021-01-27 08:29:30

问题


My automated tests used to run smoothly, but we moved the QA environment to a different server, and now the tests are failing because the it keeps tries to click on elements that are still loading and greyed out/disabled. Here is part of the code that worked just fine on the previous server:

while ( less than 7 seconds )
if (driver.FindElements(by).Count > 0)
{
      if (driver.FindElement(by).Enabled && driver.FindElement(by).Displayed)
            break;
}
else 
{ go back to while loop }

The problem is that driver.FindElement(by).Enabled keeps evaluating to 'true' (I found out during debugging) when the page is clearly still loading and the entire page is still greyed out, causing the driver to proceed to try to click on the greyed out element, and then of course the test fails with an exception. Has anyone encountered this kind of issue? I use Webdriver with C# and NUnit, run test in IE. Thanks.


回答1:


Pretty old question but I will still respond just in case. The answer is right here in the help of IWebElement.Enabled. It quotes

The Enabled property will generally return true for everything except explicitly disabled input elements.




回答2:


The Enabled method only works for Input elements and radio buttons. For non Input elements use GetAttribute("disabled"). This will return "true" if disabled="disabled", or null if still enabled.



来源:https://stackoverflow.com/questions/26186999/selenium-webdriver-c-sharp-element-enabled-evaluating-to-true-when-element-is-st

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!