Localizando elementos en la página web (I)

in #selenium7 years ago

How are we going to find elements in the pages that we load?

  1. Using the WebDriver instance itself
  2. On a WebElement

You have to know that there will be always some methods that helps us to Find Element (which returns a WebElement object matching the query and throws and exception if such an element cannot be found) and its plural Find Elements (which returns a list of WebElements, possibly empty if no DOM elements match the query).

Let's find out different BY strategies

By ID

The quickest way to locate an element. Bear in mind that the website you are browsing needs uniques ID, otherwise you are going to get an error. An example would be:

1) element = driver.find_element_by_id("value_ID_searched")

2) from selenium.webdriver.common.by import By
element = driver.find_element(by=By.ID, value="value_ID_searched")
Sort:  

Sorry, the title is in my native language, it should say: "Locating UI Elements (WebElements)" 🙏🏻🙈😃