问题
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