1

I am new to selenium and i have been trying for some time to click on an anchor element. I have tried css-selector,lint_text,xpath,absolute xpath but i am still unable to click on it and instead i am getting this error message:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: Driver Schedule

Does anyone know how to get around this ?

Update: I am getting this error now:

selenium.common.exceptions.ElementClickInterceptedException: Message: Element <a href="#/schedule/weekly-view"> is not clickable at point (326,333) because another element <div class="app-spinner-layer active"> obscures it

1 Answers1

1

To click() on the element with text as Driver Schedule as it is an <a> node you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using LINK_TEXT:

    WebDriverWait(driver, 20).until(EC.invisibility_of_element((By.CSS_SELECTOR, "div.app-spinner-layer.active")))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Driver Schedule"))).click()
    
  • Using PARTIAL_LINK_TEXT:

    WebDriverWait(driver, 20).until(EC.invisibility_of_element_located((By.XPATH, "//div[@class='app-spinner-layer active']")))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Driver Schedule"))).click()
    
  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.invisibility_of_element((By.CSS_SELECTOR, "div.app-spinner-layer.active")))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li.pll a[href$='weekly-view']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.invisibility_of_element_located((By.XPATH, "//div[@class='app-spinner-layer active']")))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(@href,'weekly-view') and contains(., 'Driver Schedule')]"))).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