当微调器使用Selenium和Python将锚元素遮挡时,如何单击该锚元素? [英] How to click on the anchor element when the spinner obscures it using Selenium and Python?

查看:258
本文介绍了当微调器使用Selenium和Python将锚元素遮挡时,如何单击该锚元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是硒的新手,并且我一直在尝试单击锚元素.我已经尝试了css-selector,lint_text,xpath,绝对xpath,但是我仍然无法单击它,相反,我收到了以下错误消息:

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

推荐答案

Driver Schedule 为文本的元素上的click(),因为它是 <a> 您必须为element_to_be_clickable()引入 WebDriverWait 节点,并且可以使用以下任一

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:

  • 使用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()

  • 使用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()
    

  • 使用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()
    

  • 使用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
    

  • 这篇关于当微调器使用Selenium和Python将锚元素遮挡时,如何单击该锚元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆