1

I'd like to get the elements by Selenium as the attached pic:

ess-cell class="data-numeric"

However, the following code didn't work even though:

find_element_by_tag_name('div')

part works correctly. Does anyone know why?

row.find_element_by_tag_name('div').find_element_by_tag_name('div').find_elements_by_tag_name('ess-cell')

enter image description here

andrewshih
  • 477
  • 6
  • 12
  • `row.find_element_by_tag_name('div').find_element_by_tag_name('div').find_elements_by_tag_name('ess-cell')` parts works, that's fine. What is the error though ? – cruisepandey Feb 19 '22 at 14:11

1 Answers1

1

To get the elements <ess-cell class="data-numeric"...> you can use either of the following Locator Strategies:

  • Using css_selector:

    elements = row.find_elements(By.CSS_SELECTOR, "div > div ess-cell.data-numeric")
    
  • Using xpath:

    elements = row.find_elements(By.XPATH, "./div/div//ess-cell[contains(@class, 'data-numeric')]")
    

Ideally you have to induce WebDriverWait for presence_of_all_elements_located() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    elements = WebDriverWait(row, 20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "div > div ess-cell.data-numeric")))
    
  • Using XPATH:

    elements = WebDriverWait(row, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "./div/div//ess-cell[contains(@class, 'data-numeric')]")))
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352