-1

This is the HTML:

<li class="Y8-fY "><a class="-nal3 " href="/example/" tabindex="0"><span class="g47SY ">1.692</span> abonniert</a></li>

I tried using XPATH with the href to find it but i just get the nosuchelement error.

LordB
  • 13
  • 1
  • 3
  • 2
    Please share your code you have tried. Also if possible share a link to that page or at least the HTML of that page – Prophet Dec 15 '21 at 08:54
  • Please provide enough code so others can better understand or reproduce the problem. – Community Dec 21 '21 at 17:50

1 Answers1

-1

To click() on the desired element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using PARTIAL_LINK_TEXT:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "abonniert"))).click()
    
  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li > a[href='/example/'] > span"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//li/a[@href='/example/']/span"))).click()
    
  • 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