0

I would like to get the title attribute from the span class = g47SY lOXF2 but I can't find the correct css path.

Here is what I tried:

Number = self.browser.find_element_by_css_selector('ul li a span').get_attribute('title')

but it does not work.

Here is the HTML:

Here is the HTML

prosoitos
  • 6,679
  • 5
  • 27
  • 41
EngineWare
  • 11
  • 1
  • 3

1 Answers1

0

To print the value of the title attribute i.e 251 you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a[href$='followers/']>span[title]"))).get_attribute("title"))
    
  • Using XPATH:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//a[contains(@href, 'followers') and contains(., 'followers')]/span"))).get_attribute("title"))
    
  • 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