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

前端 未结 1 457
星月不相逢
星月不相逢 2020-12-12 03:08

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 cl

相关标签:
1条回答
  • 2020-12-12 03:28

    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
      
    0 讨论(0)
提交回复
热议问题