๐งฉ Selenium WebElement Operations in Python
WebElement operations are actions performed on web elements such as buttons, input fields, checkboxes, links, and dropdowns. These operations form the core interaction layer of Selenium automation.
๐ฑ Click Operation
Used to click on buttons, links, checkboxes, and radio buttons.
driver.find_element(By.ID, "loginBtn").click()---
⌨ Send Keys (Input Text)
Used to enter text into input fields.
driver.find_element(By.ID, "username").send_keys("admin")
driver.find_element(By.ID, "password").send_keys("12345")
---
๐งน Clear Text Field
Clears existing text from an input field.
driver.find_element(By.ID, "search").clear()---
๐ Get Text
Used to fetch visible text from an element.
text = driver.find_element(By.ID, "message").text print(text)---
๐ท Get Attribute
Used to fetch attribute value of an element.
value = driver.find_element(By.ID, "email").get_attribute("value")
placeholder = driver.find_element(By.ID, "email").get_attribute("placeholder")
---
๐ isDisplayed()
Checks whether element is visible on the UI.
status = driver.find_element(By.ID, "submit").is_displayed() print(status)---
⚙ isEnabled()
Checks whether element is enabled or disabled.
status = driver.find_element(By.ID, "submit").is_enabled() print(status)---
✔ isSelected()
Checks whether checkbox or radio button is selected.
status = driver.find_element(By.ID, "remember").is_selected() print(status)---
- Always use waits before operations
- Verify element visibility before action
- Use stable locators
- Validate element state before click
- Log every major action
WebElement operations are the heart of Selenium automation. Mastering these methods allows you to build reliable, stable, and scalable automation frameworks.
No comments:
Post a Comment