How to Use EC.presence_of_element_located with Class Attribute
When using selenium's EC.presence_of_element_located method with WebDriverWait, you canspecify an element to find by its class attribute instead of its ID. Here's how to do it:
The original code:
element = WebDriverWait(driver,100).until(EC.presence_of_element_located((By.ID, "tabla_evolucion")))
attempts to find an element by its ID. To find an element by its class instead, change "By.ID" to "By.CLASS" and provide the class name:
element = WebDriverWait(driver,100).until(EC.presence_of_element_located((By.CLASS, "ng-binding ng-scope")))
Note: Avoid using presence_of_element_located for interactive actions. Instead, prefer visibility_of_element_located or element_to_be_clickable.
Additionally:
# CSS_SELECTOR element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located( (By.CSS_SELECTOR, ".ng-binding.ng-scope#tabla_evolucion"))) # XPATH element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located( (By.XPATH, "//*[@class='ng-binding ng-scope' and @id='tabla_evolucion']")))
The above is the detailed content of How to Locate Elements by Class Attribute Using Selenium's EC.presence_of_element_located?. For more information, please follow other related articles on the PHP Chinese website!