Popular Searches
Popular Course Categories
Popular Courses

Is Enabled

Working with Web Elements

isEnabled() in Selenium

isEnabled() is a Selenium WebDriver method used to check whether a web element is currently enabled and available for interaction according to WebDriver's enabled-state rules. It returns a boolean value: true when the element is enabled and false when the element is disabled.

It is commonly used with form controls such as buttons, text fields, checkboxes, radio buttons, select controls, and submit buttons. In Selenium automation, isEnabled() is useful for validating whether users can interact with a particular control at a specific point in a test.

JustAcademy's Selenium Automation Testing Course covers Selenium WebDriver, locators, WebElements, TestNG, data-driven testing, Page Object Model, cross-browser testing, automation frameworks, and real-time projects. These concepts provide the foundation for using WebElement methods such as isEnabled() in practical automation testing. Selenium Training Course

To explore the course through a practical demo session, visit Selenium Course Demo.


1. What is isEnabled()?

isEnabled() is a method of Selenium's WebElement interface. It checks whether the located element is enabled for interaction.

The method returns a boolean value:

  • true → The element is enabled.
  • false → The element is disabled.

For example, a Submit button may initially be disabled until the user enters all required information. Selenium can use isEnabled() to verify this state.


2. Basic Syntax

boolean status = element.isEnabled();

Here, element represents a Selenium WebElement and status stores the enabled state returned by Selenium.


3. Simple Example

WebElement button = driver.findElement(By.id("submitBtn"));

boolean enabled = button.isEnabled();

System.out.println("Button enabled: " + enabled);

If the button is enabled, the output will be:

Button enabled: true

If the button is disabled, the output will be:

Button enabled: false


4. Why isEnabled() is Important?

Modern web applications frequently enable or disable controls based on user actions, validation rules, permissions, application state, or data availability.

For example:

  • Login button becomes enabled after valid credentials are entered.
  • Checkout button becomes enabled after required information is completed.
  • Submit button becomes enabled after form validation succeeds.
  • Next button becomes enabled after selecting a required option.
  • Payment button becomes enabled after accepting terms and conditions.

Using isEnabled(), automation scripts can verify these application states.


5. isEnabled() Return Type

The return type of isEnabled() is boolean.

boolean result = element.isEnabled();

Return ValueMeaning
trueThe element is enabled.
falseThe element is disabled.


6. isEnabled() with Button

One of the most common uses of isEnabled() is checking whether a button is enabled.

WebElement loginButton = driver.findElement(By.id("loginBtn"));

if(loginButton.isEnabled()){

    System.out.println("Login button is enabled");

}else{

    System.out.println("Login button is disabled");

}


7. isEnabled() with Text Input

It can also be used with input fields.

WebElement username = driver.findElement(By.id("username"));

if(username.isEnabled()){

    username.sendKeys("admin");

}

This example enters data only when the username field is enabled.


8. isEnabled() with Password Field

WebElement password = driver.findElement(By.id("password"));

System.out.println("Password field enabled: " + password.isEnabled());


9. isEnabled() with Checkbox

A checkbox can also be checked for its enabled state.

WebElement termsCheckbox = driver.findElement(By.id("terms"));

if(termsCheckbox.isEnabled()){

    System.out.println("Terms checkbox can be interacted with");

}


10. isEnabled() with Radio Button

WebElement maleRadio = driver.findElement(By.id("male"));

if(maleRadio.isEnabled()){

    maleRadio.click();

}


11. isEnabled() with Select Element

A select control can also be checked before interacting with it.

WebElement country = driver.findElement(By.id("country"));

if(country.isEnabled()){

    Select select = new Select(country);

    select.selectByVisibleText("India");

}


12. HTML disabled Attribute

HTML form controls can be disabled using the disabled attribute.

<button id="submitBtn" disabled>Submit</button>

For such a button, Selenium can report:

WebElement submit = driver.findElement(By.id("submitBtn"));

System.out.println(submit.isEnabled());

The result is normally:

false


13. Enabled Button Example

<button id="submitBtn">Submit</button>

WebElement submit = driver.findElement(By.id("submitBtn"));

System.out.println(submit.isEnabled());

For an enabled button, Selenium normally returns:

true


14. Disabled Input Example

<input type="text" id="username" disabled>

WebElement username = driver.findElement(By.id("username"));

System.out.println(username.isEnabled());

The expected result is:

false


15. Enabled Input Example

<input type="text" id="username">

WebElement username = driver.findElement(By.id("username"));

System.out.println(username.isEnabled());

The expected result is:

true


16. isEnabled() Does Not Check Visibility

isEnabled() and isDisplayed() perform different checks. An element can be enabled but not currently displayed.

WebElement element = driver.findElement(By.id("myElement"));

System.out.println("Enabled: " + element.isEnabled());

System.out.println("Displayed: " + element.isDisplayed());

MethodPurposeReturn Type
isEnabled()Checks enabled stateboolean
isDisplayed()Checks displayed stateboolean


17. isEnabled() Does Not Check Selection

isEnabled() does not tell whether a checkbox, radio button, or option is selected.

WebElement checkbox = driver.findElement(By.id("subscribe"));

System.out.println("Enabled: " + checkbox.isEnabled());

System.out.println("Selected: " + checkbox.isSelected());

These are two different states.

  • isEnabled() → Can the control be interacted with?
  • isSelected() → Is the control currently selected?


18. isEnabled() vs isDisplayed() vs isSelected()

MethodChecksReturnTypical Usage
isEnabled()Enabled statebooleanButtons, inputs, controls
isDisplayed()Displayed statebooleanVisibility checks
isSelected()Selection statebooleanCheckbox, radio, option


19. Checking Both Displayed and Enabled

Sometimes a test needs to verify that an element is both visible and enabled.

WebElement loginButton = driver.findElement(By.id("loginBtn"));

if(loginButton.isDisplayed() && loginButton.isEnabled()){

    System.out.println("Login button is visible and enabled");

}


20. Checking Enabled Before Clicking

WebElement submitButton = driver.findElement(By.id("submitBtn"));

if(submitButton.isEnabled()){

    submitButton.click();

}else{

    System.out.println("Submit button is disabled");

}

This can be useful when the application intentionally disables a control until some condition is satisfied.


21. isEnabled() Is an Immediate Check

isEnabled() checks the element's state at the moment the method is executed. It does not automatically wait for the element to become enabled.

boolean enabled = button.isEnabled();

If the application enables the button two seconds later, the above statement does not wait two seconds and check again.


22. Waiting for an Element to Become Enabled

For dynamic applications, an explicit wait is usually more appropriate than repeatedly calling isEnabled() manually.

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

WebElement button = wait.until(

    ExpectedConditions.elementToBeClickable(By.id("submitBtn"))

);

button.click();

elementToBeClickable() is commonly used when the test needs an element that is visible and enabled for clicking.


23. Custom Wait Using isEnabled()

If the test specifically needs to wait for the enabled state, a custom condition can be used.

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

wait.until(driver -> driver.findElement(By.id("submitBtn")).isEnabled());

For highly dynamic pages, locating the element inside the wait condition can be safer because the DOM may be refreshed or replaced.


24. Login Button Example

Consider a login page where the Login button is disabled until the required fields are completed.

WebElement username = driver.findElement(By.id("username"));

WebElement password = driver.findElement(By.id("password"));

WebElement loginButton = driver.findElement(By.id("loginBtn"));

username.sendKeys("admin");

password.sendKeys("admin123");

if(loginButton.isEnabled()){

    loginButton.click();

}


25. Form Validation Example

A form may keep the Submit button disabled until all mandatory fields contain valid information.

WebElement submit = driver.findElement(By.id("submit"));

System.out.println("Before entering data: " + submit.isEnabled());

driver.findElement(By.id("name")).sendKeys("Rahul");

driver.findElement(By.id("email")).sendKeys("[email protected]");

System.out.println("After entering data: " + submit.isEnabled());


26. Terms and Conditions Example

Some applications enable a Submit or Continue button only after the user accepts terms and conditions.

WebElement terms = driver.findElement(By.id("terms"));

WebElement continueButton = driver.findElement(By.id("continue"));

terms.click();

if(continueButton.isEnabled()){

    continueButton.click();

}


27. E-Commerce Example

In an e-commerce application, the Checkout button may become enabled only after a valid product or shipping information is available.

WebElement checkout = driver.findElement(By.id("checkout"));

if(checkout.isEnabled()){

    checkout.click();

}else{

    System.out.println("Checkout button is disabled");

}


28. Payment Button Example

WebElement paymentButton = driver.findElement(By.id("payNow"));

if(paymentButton.isEnabled()){

    System.out.println("Payment button is ready for interaction");

}else{

    System.out.println("Payment button is disabled");

}


29. XPath with isEnabled()

isEnabled() can be used with elements located using XPath.

WebElement submit = driver.findElement(

    By.xpath("//button[@type='submit']")

);

System.out.println(submit.isEnabled());


30. CSS Selector with isEnabled()

WebElement submit = driver.findElement(

    By.cssSelector("button[type='submit']")

);

System.out.println(submit.isEnabled());


31. Checking Multiple Buttons

List<WebElement> buttons = driver.findElements(By.tagName("button"));

for(WebElement button : buttons){

    System.out.println("Button enabled: " + button.isEnabled());

}


32. Checking Multiple Input Fields

List<WebElement> inputs = driver.findElements(By.cssSelector("input"));

for(WebElement input : inputs){

    System.out.println(

        input.getAttribute("name") + " enabled: " + input.isEnabled()

    );

}


33. TestNG Assertion with isEnabled()

In TestNG, isEnabled() can be combined with assertions.

WebElement loginButton = driver.findElement(By.id("loginBtn"));

Assert.assertTrue(loginButton.isEnabled());


34. Verify Element Is Disabled

WebElement submitButton = driver.findElement(By.id("submitBtn"));

Assert.assertFalse(submitButton.isEnabled());


35. Verify Element Becomes Enabled

WebElement submitButton = driver.findElement(By.id("submitBtn"));

Assert.assertTrue(submitButton.isEnabled());

submitButton.click();


36. isEnabled() and getAttribute("disabled")

It is possible to inspect the HTML using getAttribute("disabled"), but this is not the same as asking WebDriver whether the element is enabled.

WebElement button = driver.findElement(By.id("submitBtn"));

System.out.println("Enabled: " + button.isEnabled());

System.out.println("Disabled attribute: " + button.getAttribute("disabled"));

When the testing requirement is specifically to verify whether a form control is enabled, isEnabled() is generally the clearer semantic check.


37. Disabled Attribute Example

<button id="submitBtn" disabled>Submit</button>

WebElement button = driver.findElement(By.id("submitBtn"));

String disabled = button.getAttribute("disabled");

boolean enabled = button.isEnabled();

System.out.println("disabled attribute: " + disabled);

System.out.println("enabled: " + enabled);


38. Disabled Fieldset

HTML can disable groups of form controls through a disabled fieldset. In such cases, the child control may not itself contain a disabled attribute even though its effective enabled state is affected.

<fieldset disabled>

    <input id="username">

    <button id="submit">Submit</button>

</fieldset>

This is one reason a semantic enabled-state check is preferable when the test intent is to verify whether the control can be enabled for interaction.


39. readonly vs disabled

readonly and disabled are different concepts.

<input id="username" readonly>

<input id="password" disabled>

A readonly text field can remain enabled according to WebDriver while preventing the user from editing its value. A disabled control is not enabled for normal interaction.

StateMeaning
readonlyValue generally cannot be edited by the user.
disabledControl is disabled for normal form interaction.


40. aria-disabled vs disabled

Modern applications may use aria-disabled="true" to communicate an application's disabled state.

<button aria-disabled="true">Submit</button>

ARIA state and native HTML disabled state are not identical. If an application uses ARIA-only state management, the automation test may need to verify the relevant application attribute or behavior separately.


41. isEnabled() Does Not Guarantee Successful Click

An element can be enabled and still fail when Selenium tries to click it. For example, another element may cover it, the DOM may change, the element may become stale, or the application may have another interaction constraint.

WebElement button = driver.findElement(By.id("submit"));

if(button.isEnabled()){

    button.click();

}

The condition confirms enabled state, but it does not guarantee that the subsequent click will succeed in every situation.


42. isEnabled() and elementToBeClickable

When the objective is specifically to click an element, Selenium's explicit wait condition elementToBeClickable() is often more suitable.

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

WebElement button = wait.until(

    ExpectedConditions.elementToBeClickable(By.id("submit"))

);

button.click();

This condition is intended for an element that is visible and enabled for clicking.


43. NoSuchElementException

If the locator cannot find the element, Selenium does not reach the isEnabled() call. The findElement() operation can throw NoSuchElementException.

WebElement button = driver.findElement(By.id("submit"));

boolean enabled = button.isEnabled();

The element must first be successfully located before its enabled state can be checked.


44. Handling Dynamic Elements

For elements that appear dynamically, explicit waits are generally preferable to immediately calling isEnabled().

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

WebElement button = wait.until(

    ExpectedConditions.elementToBeClickable(By.id("submit"))

);

button.click();


45. StaleElementReferenceException

Modern applications may rebuild elements through JavaScript or framework rendering. If a stored WebElement refers to an old DOM node, Selenium may throw StaleElementReferenceException.

WebElement button = driver.findElement(By.id("submit"));

driver.navigate().refresh();

boolean enabled = button.isEnabled();

In dynamic situations, locating the element again can be safer.


46. Safer Dynamic Check

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

wait.until(driver -> driver.findElement(By.id("submit")).isEnabled());


47. Page Object Model with isEnabled()

In the Page Object Model, enabled-state checks can be encapsulated inside page classes.

public boolean isLoginButtonEnabled(){

    return loginButton.isEnabled();

}

The test class can then use:

Assert.assertTrue(loginPage.isLoginButtonEnabled());


48. Complete Page Object Example

public class LoginPage {

    private WebDriver driver;

    private By username = By.id("username");

    private By password = By.id("password");

    private By loginButton = By.id("loginBtn");

 

    public LoginPage(WebDriver driver){

        this.driver = driver;

    }

 

    public void enterUsername(String value){

        driver.findElement(username).sendKeys(value);

    }

 

    public void enterPassword(String value){

        driver.findElement(password).sendKeys(value);

    }

 

    public boolean isLoginButtonEnabled(){

        return driver.findElement(loginButton).isEnabled();

    }

 

    public void clickLogin(){

        driver.findElement(loginButton).click();

    }

}


49. Test Class Example

LoginPage loginPage = new LoginPage(driver);

loginPage.enterUsername("admin");

loginPage.enterPassword("admin123");

Assert.assertTrue(loginPage.isLoginButtonEnabled());

loginPage.clickLogin();


50. Dynamic Login Workflow

Open Login Page

      ↓

Enter Username

      ↓

Enter Password

      ↓

Application Validates Credentials

      ↓

Login Button Becomes Enabled

      ↓

Check isEnabled()

      ↓

Click Login Button


51. Registration Form Workflow

Open Registration Form

      ↓

Enter Required Details

      ↓

Accept Terms

      ↓

Client-Side Validation

      ↓

Submit Button Enabled

      ↓

Verify isEnabled()

      ↓

Submit Form


52. E-Commerce Checkout Workflow

Add Product to Cart

      ↓

Open Cart

      ↓

Enter Shipping Details

      ↓

Select Delivery Method

      ↓

Application Validates Information

      ↓

Checkout Button Enabled

      ↓

Verify isEnabled()

      ↓

Proceed to Checkout


53. Checking Several Form Controls

WebElement name = driver.findElement(By.id("name"));

WebElement email = driver.findElement(By.id("email"));

WebElement phone = driver.findElement(By.id("phone"));

WebElement submit = driver.findElement(By.id("submit"));

 

System.out.println("Name enabled: " + name.isEnabled());

System.out.println("Email enabled: " + email.isEnabled());

System.out.println("Phone enabled: " + phone.isEnabled());

System.out.println("Submit enabled: " + submit.isEnabled());


54. Conditional Interaction

WebElement nextButton = driver.findElement(By.id("next"));

if(nextButton.isEnabled()){

    nextButton.click();

}else{

    System.out.println("Next button is not enabled yet");

}


55. Checking Element State Before sendKeys()

WebElement username = driver.findElement(By.id("username"));

if(username.isEnabled()){

    username.clear();

    username.sendKeys("admin");

}


56. Checking Element State Before Selecting

WebElement country = driver.findElement(By.id("country"));

if(country.isEnabled()){

    Select select = new Select(country);

    select.selectByVisibleText("India");

}


57. Using isEnabled() with Explicit Wait

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));

wait.until(driver -> {

    WebElement submit = driver.findElement(By.id("submit"));

    return submit.isDisplayed() && submit.isEnabled();

});

For a fully dynamic element that can be replaced in the DOM, locating it again inside the condition is safer than relying on an old WebElement reference.


58. Checking Visibility and Enabled State Together

WebElement button = driver.findElement(By.id("submit"));

boolean ready = button.isDisplayed() && button.isEnabled();

System.out.println("Button ready: " + ready);


59. Optional Elements

When an element may not exist on a page, findElements() can be useful because it returns an empty list instead of throwing NoSuchElementException.

List<WebElement> buttons = driver.findElements(By.id("submit"));

if(!buttons.isEmpty()){

    System.out.println("Enabled: " + buttons.get(0).isEnabled());

}else{

    System.out.println("Submit button is not present");

}


60. Checking Disabled State with TestNG

WebElement submit = driver.findElement(By.id("submit"));

Assert.assertFalse(submit.isEnabled());


61. Checking Enabled State with TestNG

WebElement submit = driver.findElement(By.id("submit"));

Assert.assertTrue(submit.isEnabled());


62. Real-World Validation Scenario

Suppose a registration form contains Name, Email, Password, Confirm Password, and Submit controls. The Submit button is disabled until all required fields are valid.

WebElement submit = driver.findElement(By.id("submit"));

Assert.assertFalse(submit.isEnabled());

 

driver.findElement(By.id("name")).sendKeys("Amit");

driver.findElement(By.id("email")).sendKeys("[email protected]");

driver.findElement(By.id("password")).sendKeys("Password123");

driver.findElement(By.id("confirmPassword")).sendKeys("Password123");

 

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

wait.until(driver -> driver.findElement(By.id("submit")).isEnabled());

 

Assert.assertTrue(driver.findElement(By.id("submit")).isEnabled());


63. Practical Project Example

A practical Selenium project can validate an e-commerce checkout process.

  1. Open the shopping application.
  2. Login with valid credentials.
  3. Search for a product.
  4. Add the product to the cart.
  5. Open the cart.
  6. Enter shipping details.
  7. Check whether the Checkout button is enabled.
  8. Proceed only when the button is enabled.
  9. Verify the payment control state.
  10. Complete the transaction workflow.


64. Complete Practical Example

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

WebElement checkout = wait.until(

    ExpectedConditions.visibilityOfElementLocated(By.id("checkout"))

);

 

boolean enabled = checkout.isEnabled();

 

if(enabled){

    checkout.click();

    System.out.println("Checkout button clicked successfully");

}else{

    System.out.println("Checkout button is disabled");

}


65. Common Mistake: Confusing Enabled with Visible

A common mistake is assuming that an enabled element must also be visible.

WebElement element = driver.findElement(By.id("submit"));

System.out.println(element.isEnabled());

System.out.println(element.isDisplayed());

These methods answer different questions and should be used according to the test requirement.


66. Common Mistake: Assuming Enabled Means Clickable

An enabled element may still have another element covering it or may be affected by a dynamic page change. Therefore, enabled state alone should not be treated as a guarantee that a click will succeed.


67. Common Mistake: Using Thread.sleep()

Avoid using fixed delays as the primary solution for waiting for an element to become enabled.

Thread.sleep(5000);

button.click();

Instead, use an explicit wait based on the actual application condition.

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

WebElement button = wait.until(

    ExpectedConditions.elementToBeClickable(By.id("submit"))

);

button.click();


68. Common Mistake: Checking Attribute Instead of State

Using only getAttribute("disabled") may not express the actual test requirement. If the requirement is "verify whether the control is enabled," use isEnabled().


69. Common Mistake: Calling isEnabled() Before Locating Element

isEnabled() belongs to WebElement, so Selenium must first locate the element.

WebElement button = driver.findElement(By.id("submit"));

boolean enabled = button.isEnabled();


70. Best Practices for isEnabled()

  • Use isEnabled() when the test requirement is about enabled or disabled state.
  • Use isDisplayed() separately when visibility matters.
  • Use isSelected() for selection state.
  • Use explicit waits for dynamically changing states.
  • Prefer stable locators such as IDs, reliable CSS selectors, or well-designed XPath expressions.
  • Use Page Object Model methods to encapsulate element-state checks.
  • Use TestNG or JUnit assertions to validate expected states.
  • Avoid unnecessary Thread.sleep() calls.
  • Remember that enabled state does not guarantee successful interaction.
  • Re-locate elements when dynamic DOM updates can make stored references stale.


71. Advantages of isEnabled()

  • Simple and easy to use.
  • Returns a clear boolean result.
  • Useful for form validation testing.
  • Useful for dynamic UI testing.
  • Helps verify button states.
  • Works with Selenium WebElement objects.
  • Can be combined with explicit waits.
  • Useful in Page Object Model frameworks.
  • Useful with TestNG and JUnit assertions.
  • Supports practical end-to-end automation scenarios.


72. Limitations and Considerations

  • It checks enabled state, not visibility.
  • It does not automatically wait for state changes.
  • It does not guarantee a successful click.
  • It can throw a stale element exception if the referenced DOM node is replaced.
  • ARIA-based application states may need separate validation.
  • Application-specific business rules may require additional checks.


73. Quick Comparison of WebElement State Methods

MethodQuestion AnsweredExample
isDisplayed()Is the element displayed?Verify error message visibility
isEnabled()Is the element enabled?Verify Submit button state
isSelected()Is the element selected?Verify checkbox state
getText()What visible text does it contain?Read heading text
getAttribute()What attribute/property-related value is exposed?Read class or value
getSize()What is the element's size?Read width and height
getLocation()Where is the element located?Read x and y coordinates


74. Interview Question: What is isEnabled() in Selenium?

Answer: isEnabled() is a Selenium WebElement method used to determine whether an element is enabled. It returns a boolean value. It is commonly used with buttons, input fields, checkboxes, radio buttons, and other form controls.


75. Interview Question: What does isEnabled() return?

Answer: It returns a boolean value. It returns true when the element is enabled and false when the element is disabled.


76. Interview Question: What is the difference between isEnabled() and isDisplayed()?

Answer: isEnabled() checks whether the element is enabled, while isDisplayed() checks whether the element is displayed according to WebDriver's displayedness semantics.


77. Interview Question: Does isEnabled() click an element?

Answer: No. isEnabled() only checks the enabled state. It does not perform any interaction. The click() method must be used to click an element.


78. Interview Question: Does isEnabled() wait for an element?

Answer: No. isEnabled() performs an immediate state check. For dynamic applications, use WebDriverWait and an appropriate expected condition or custom condition.


79. Interview Question: Can an enabled element still fail to click?

Answer: Yes. An enabled element may still be affected by overlays, layout changes, stale references, or other application conditions. Therefore, isEnabled() should not be treated as a complete guarantee of click success.


80. Interview Question: What is the difference between disabled and readonly?

Answer: A disabled control is not enabled for normal interaction, while a readonly field can generally remain enabled but does not allow the user to edit its value in the normal way.


81. Interview Question: How do you wait until an element becomes enabled?

Answer: For a click operation, use an explicit wait with ExpectedConditions.elementToBeClickable(). When the requirement is specifically the enabled state, a custom wait condition can check isEnabled().

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

wait.until(driver -> driver.findElement(By.id("submit")).isEnabled());


82. Interview Question: How do you verify that a button is disabled?

WebElement button = driver.findElement(By.id("submit"));

Assert.assertFalse(button.isEnabled());


83. Interview Question: How do you verify that a button is enabled?

WebElement button = driver.findElement(By.id("submit"));

Assert.assertTrue(button.isEnabled());


84. Interview Question: Can isEnabled() be used with XPath?

Answer: Yes. Selenium first locates the element using XPath and then calls isEnabled().

WebElement button = driver.findElement(

    By.xpath("//button[@type='submit']")

);

boolean enabled = button.isEnabled();


85. Interview Question: Can isEnabled() be used with CSS Selector?

Answer: Yes.

WebElement button = driver.findElement(

    By.cssSelector("button[type='submit']")

);

boolean enabled = button.isEnabled();


86. Interview Question: Which Selenium interface provides isEnabled()?

Answer: The WebElement interface provides the isEnabled() method in Selenium WebDriver.


87. Practical Checklist

  • Locate the element correctly.
  • Call isEnabled() on the WebElement.
  • Store the returned boolean when needed.
  • Use isDisplayed() separately for visibility.
  • Use isSelected() separately for selection.
  • Use explicit waits for dynamic enabled states.
  • Use assertions for expected states.
  • Handle dynamic DOM changes carefully.
  • Do not assume enabled means click will always succeed.
  • Use Page Object Model for maintainable automation frameworks.


88. Complete Selenium Example

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.ExpectedConditions;

import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

 

public class IsEnabledExample {

    public static void main(String[] args) {

        WebDriver driver = new ChromeDriver();

 

        driver.get("https://example.com");

 

        WebDriverWait wait = new WebDriverWait(

            driver,

            Duration.ofSeconds(10)

        );

 

        WebElement submit = wait.until(

            ExpectedConditions.visibilityOfElementLocated(

                By.id("submit")

            )

        );

 

        if(submit.isEnabled()){

            System.out.println("Submit button is enabled");

        }else{

            System.out.println("Submit button is disabled");

        }

 

        driver.quit();

    }

}


89. Real-World Automation Flow

Start Test

    ↓

Open Web Application

    ↓

Locate Web Element

    ↓

Check isDisplayed()

    ↓

Check isEnabled()

    ↓

If Enabled

    ↓

Perform Interaction

    ↓

Verify Result

    ↓

Continue Test

    ↓

End Test


90. Summary

isEnabled() is an important Selenium WebElement method for validating whether an element is enabled for interaction. It returns a boolean value and is especially useful for testing dynamic buttons, input fields, checkboxes, radio buttons, select controls, and form submission workflows.

For reliable automation, remember that isEnabled() checks enabled state only. It does not replace isDisplayed(), isSelected(), explicit waits, or application-specific validation. When a control changes state dynamically, use an appropriate explicit wait and re-locate elements when necessary to handle DOM updates safely.

For structured Selenium learning covering WebDriver, WebElements, locators, TestNG, automation frameworks, Page Object Model, data-driven testing, and real-time projects, visit JustAcademy Selenium Training.

For a practical introduction or course demonstration, visit Register for Selenium Course Demo.

whatsapp