selenium
  1. selenium-webelement-commands

WebElement Commands - (Selenium WebDriver)

Syntax:

<WebElement>.<command>()

Example:

from selenium import webdriver
driver = webdriver.Chrome(executable_path="path/to/chromedriver")
driver.get("https://www.google.com")

# Find search bar and search button
search_bar = driver.find_element_by_name("q")
search_btn = driver.find_element_by_name("btnK")

# Type a query and submit the form
search_bar.send_keys("Selenium WebDriver")
search_btn.click()

# Find all the search results and get their text
search_results = driver.find_elements_by_css_selector("div.g")
for result in search_results:
    print(result.text)

Output:

The above example will open Google, search for "Selenium WebDriver", and print the text of the search results.

Explanation:

WebElement commands are used to interact with web elements on a webpage using Selenium WebDriver. These commands are used to perform various actions on the web elements such as clicking a button, filling a form, selecting an option from a dropdown, etc.

Use:

The WebElement commands are used to automate the testing of web applications. They can be used to perform various tasks such as filling forms, clicking buttons, checking checkboxes, selecting options from dropdowns, etc.

Important Points:

  • Some of the commonly used WebElement commands are click(), send_keys(), submit(), clear(), get_attribute(), is_displayed(), is_enabled(), is_selected(), etc.
  • WebElement commands can only be used on web elements that have been found using the find_element_by_* commands.
  • WebElement commands can be chained together to perform multiple actions on a single element.

Summary:

In summary, WebElement commands are used to interact with web elements on a webpage using Selenium WebDriver. They are used to automate the testing of web applications and can be used to perform various tasks such as filling forms, clicking buttons, checking checkboxes, selecting options from dropdowns, etc.

Published on: