selenium.webdriver.common.by

The By implementation.

Classes

By()

Set of supported locator strategies.

class selenium.webdriver.common.by.By[source]

Set of supported locator strategies.

ID: – Select the element by its ID.

>>> element = driver.find_element(By.ID, 'myElement')

XPATH:

Select the element via XPATH.
  • absolute path

  • relative path

>>> element = driver.find_element(By.XPATH, '//html/body/div')

NAME:

Select the element by its name attribute.

>>> element = driver.find_element(By.NAME, 'myElement')

TAG_NAME:

Select the element by its tag name.

>>> element = driver.find_element(By.TAG_NAME, 'div')

CLASS_NAME:

Select the element by its class name.

>>> element = driver.find_element(By.CLASS_NAME, 'myElement')

CSS_SELECTOR:

Select the element by its CSS selector.

>>> element = driver.find_element(By.CSS_SELECTOR, 'div.myElement')
ID = 'id'
XPATH = 'xpath'
NAME = 'name'
TAG_NAME = 'tag name'
CLASS_NAME = 'class name'
CSS_SELECTOR = 'css selector'
classmethod register_custom_finder(name: str, strategy: str) None[source]
classmethod get_finder(name: str) str | None[source]
classmethod clear_custom_finders() None[source]