尝试单击中的复选框时,ElementClickInterceptedExceptionsurveymonkey.com网站通过硒和Python

2024-06-02 06:09:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我在玩一个小挑战,它被设置为自动执行survey monkey的表单响应,为了这个例子的目的,我设置了一个虚拟的调查。在

本质上,selenium无法单击该框,原因是出现了一个按钮显示错误,使其模糊。在

ElementClickInterceptedException: Message: Element  input id="234136539_1601280849" class="checkbox-button-input " name="234136539[]" type="checkbox"> is not clickable at point (237.5,345.5) because another element span class="checkbox-button-display "> obscures it

我已经看了this question,它是Java特有的,我不太清楚如何克服这个问题,我尝试过隐式等待,点击它周围的框,但是在没有学习Java的情况下,有点迷失了从何开始。在

^{pr2}$

此代码应该复制虚拟调查的问题。在


Tags: 目的表单inputselenium错误原因buttonjava
2条回答

要单击与文本关联的第二个复选框,您必须诱导WebDriverWait,以便元素可单击,您可以使用以下解决方案:

  • 代码块:

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    driver = webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe') 
    driver.get('https://www.surveymonkey.com/r/L9DJGXR') 
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='question-body clearfix notranslate ']//following::label[2]"))).click()
    
  • 浏览器快照:

surveymonkey

右键单击“我”旁边的复选框并选择“检查…”。。。选择了什么元素?SPAN。这是因为SPAN与要单击的INPUT重叠。这就是那个错误告诉你的。您正试图单击被另一个元素覆盖的元素。Selenium不能“看到”页面,看不到下面的元素是否真的被遮住了。在

{{cd5>的解决方案是。你做哪一个都不重要,两个都会有用的。下面是两个CSS选择器

[id='234136539_1601280849'] + label // clicks the LABEL
^ has this ID
                            ^ '+' means sibling
                              ^ LABEL tag

[id='234136539_1601280849'] + label > span // clicks the SPAN
everything is the same as above until...
                                    ^ '>' means child
                                      ^ SPAN tag

相关问题 更多 >