How to click on the anchor element when the spinner obscures it using Selenium and Python?

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
    

Leave a Comment