0

I am trying to check if button is enabled or disabled on the webpage. I have tried below methods but they all return true even if the button is disabled.

Boolean z = Driver.findElement(By.id("ext-gen81")).isEnabled();
System.out.println(z);
Boolean y = Driver.findElement(By.id("ext-gen72")).isEnabled();
System.out.println(y);
Boolean u = Driver.findElement(By.id("ext-gen81")).isDisplayed();
System.out.println(u);
Boolean v = Driver.findElement(By.id("ext-gen72")).isDisplayed();
System.out.println(v);

Also html text for button is same when it is enabled or disabled.

Can anyone please suggest any better idea.

3
  • <button id="ext-gen81" class="x-btn-text x-tbar-page-next" type="button"/> Commented Jun 26, 2015 at 17:28
  • If there is no change in html, then CSS will change... Observe the CSS property which is changing... And get that value using getCssProperty method... Commented Jun 27, 2015 at 7:09
  • Are you using extJS if yes which version Commented Jun 27, 2015 at 17:09

1 Answer 1

-1

From your comment

<button id="ext-gen81" class="x-btn-text x-tbar-page-next" type="button"/>

It looks like ExtJS Application.If so you can use the Selenium's element.isEnabled() to check whether element is enabled or not.For that you have to check the class attribute of the element and check whether it contains disabled css or not

The following snippet is specific for ExtJS element to check if it enabled or not.Because if element is disabled in ExtJS the class will have some of the css likex-item-disabled x-disabled. I guess it will help you.If not follow the same approach and change the regex to suit your needs

public static Boolean isElementEnabled(WebElement element) {
    String className = element.getAttribute("class");
    return className.matches(".+(x-.+-disabled)+");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.