1

This is my code-->

element = driver.find_elements_by_css_selector("[aria-label='收回讚']")

It doesn't work, it creates an None type. Any help is appreciated! Thanks in advance!

update:

my update code:

try:
     element = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.XPATH, "//*[aria-label='收回讚']")))
     #check if unlike path exisit
  

except:
    element = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.XPATH, "//*[aria-label='讚']")))
    element.click()
    #if not find like path and click it

this is a reference of the html

Math Noob
  • 75
  • 1
  • 10

1 Answers1

2

To find the element you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "[aria-label='收回讚']")))
    
  • Using XPATH:

    element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//*[@aria-label='收回讚']")))
    
  • 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
    

References

You can find a couple of relevant detailed descroptions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352