0

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

1 Answers1

0

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:

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • @Yu-ChuehWang There was a minor bug which I corrected. Checkout the updated answer and let me know the status. – DebanjanB Dec 21 '20 at 14:56