is_enabled Method

The is_enabled() method in Selenium is used to check whether a web element is enabled or not. This is typically used to verify if an input element, button, or other interactive elements are enabled for interaction (e.g. if they are clickable or can receive input).

Here’s a basic example of how to use is_enabled() in Python with Selenium:

Example:

from selenium import webdriver
from selenium.webdriver.common.by import By

# Set up the driver (assuming you're using Chrome)
driver = webdriver.Chrome()

# Open a webpage of any website
driver.get('https://www.google.com')

# Locate the element (e.g., a button or input field)
element = driver.find_element(By.NAME, 'q')

# Check if the element is enabled ot not
if element.is_enabled():
    print("The element is enabled.")
else:
    print("The element is disabled.")

# Close the browser
driver.quit()

Explanation:

  • element.is_enabled() returns True if the element is enabled, and False if it is disabled.
  • You can use this method before interacting with elements like buttons or input fields to ensure that they are available for interaction.