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).
- Selenium Features
- Selenium Installation
- Selenium Locators
- XPath Fundamentals
- CSS Selectors Methods
- Different Browsers Execution
- find_element & find_elements
- Check Enabled Status
- Check Displayed Status
- Check Selected Status
- Selenium Waits
- Send_keys Method
- Click Method
- Get Text
- Get Attribute Value
- Get Current URL
- Forward, Back, Refresh
- Take Screenshot
- Handle Browser Tabs
- Handle iframe
- Mouse Hover
- Context-Click
- Drag & Drop
- Handle Alerts
- Handle Dropdown
- Execute Javascript
- Scroll To element
- Headless Mode Execution
- Chrome Options
- Keyboard Action
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()
returnsTrue
if the element is enabled, andFalse
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.