【问题标题】:ElementClickInterceptedException: Message: element click intercepted Element is not clickable error clicking a radio button using Selenium and PythonElementClickInterceptedException:消息:元素单击被拦截元素不可点击错误单击使用 Selenium 和 Python 的单选按钮
【发布时间】:2020-07-14 19:54:32
【问题描述】:

我正在尝试单击第一个框(ASN / DSD)

但我收到此错误消息:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: 
Element <input type="radio" name="docTypes" ng-model="$ctrl.documentTypes.selected" id="documentType-0" ng-change="$ctrl.onChangeDocumentType()" ng-value="documentType" tabindex="0" class="ng-pristine ng-untouched ng-valid ng-empty" value="[object Object]" aria-invalid="false"> 
is not clickable at point (338, 202). 
Other element would receive the click:
 <label translate-attr="{title: 'fulfillment.documentAction.createNew.modal.documentType.document.title'}" translate-values="{documentName: documentType.name}" for="documentType-0" translate="ASN - DSD" tabindex="0" title="Select ASN - DSD document type">...</label>
  (Session info: chrome=83.0.4103.116)

我知道我输入了正确的 iframe,因为它可以找到元素,而不是点击它。 我的代码是

driver.switch_to.default_content()
iframes = driver.find_elements_by_tag_name("iframe")
driver.switch_to.frame(iframes[0])
time.sleep(5)
driver.find_element_by_xpath('//*[@id="documentType-0"]').click()

我看到 DebanjanB 在这里回答了类似的问题:link

我正在尝试使用执行脚本的第三个解决方案。我不知道该模型使用什么 CSS 选择器。 模型是这样的

WebDriverWait(driver, 20).until(EC.invisibility_of_element((By.CSS_SELECTOR, "span.taLnk.ulBlueLinks")))
driver.execute_script("arguments[0].click();", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='loadingWhiteBox']"))))

我的问题是我需要在第一行使用什么 css 选择器,然后它只是我在第二行使用的初始 xpath?

这是供参考的 HTML。当我尝试点击输入部分时,我收到点击拦截错误。如果使用xpath点击标签标签,它不会出错但也不会点击它。它只是移动到下一段代码而不做任何事情。

<li ng-repeat="documentType in selectDocumentType.documentTypes.displayedList |
orderBy:selectDocumentType.formOrder"> 

<input type="radio" name="docTypes" ng
model="selectDocumentType.documentTypes.selected" id="documentType-0" ng-value="documentType"
tabindex="0" class="ng-valid ng-not-empty ng-dirty ng-valid-parse ng-touched" value="[object Object]"
aria-invalid="false"> 

<label translate-attr="{title:'fulfillment.documentAction.createNew.modal.documentType.document.title'}" 
translate-values={documentName: documentType.name}" for="documentType-0" translate="ASN - DSD" tabindex="0" title=
"Select ASN - DSD document type"><span>ASN - DSD</span></label> </li>

关于如何停止点击被拦截的任何建议?

【问题讨论】:

    标签: javascript python selenium webdriver webdriverwait


    【解决方案1】:

    此错误消息...

    selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: 
    Element <input type="radio" name="docTypes" ng-model="$ctrl.documentTypes.selected" id="documentType-0" ng-change="$ctrl.onChangeDocumentType()" ng-value="documentType" tabindex="0" class="ng-pristine ng-untouched ng-valid ng-empty" value="[object Object]" aria-invalid="false"> 
    is not clickable at point (338, 202). 
    Other element would receive the click:
     <label translate-attr="{title: 'fulfillment.documentAction.createNew.modal.documentType.document.title'}" translate-values="{documentName: documentType.name}" for="documentType-0" translate="ASN - DSD" tabindex="0" title="Select ASN - DSD document type">...</label>
    

    ...暗示所需元素不可点击,因为某些其他元素会遮挡它。


    所需的元素是Angular 元素,因此要在元素上调用click(),您必须为WebDriverWait 诱导WebDriverWait,您可以使用以下Locator Strategies 之一:

    • 使用CSS_SELECTOR

      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label[for='documentType-0']"))).click()
      
    • 使用XPATH

      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@for='documentType-0']"))).click()
      
    • 注意:您必须添加以下导入:

      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.common.by import By
      from selenium.webdriver.support import expected_conditions as EC
      

    更新

    您也可以使用execute_script() 方法,如下所示:

    • 使用CSS_SELECTOR

      driver.execute_script("arguments[0].click();", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label[for='documentType-0']"))))
      
    • 使用XPATH

      driver.execute_script("arguments[0].click();", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@for='documentType-0']"))))
      

    参考文献

    您可以在以下位置找到一些相关讨论:

    【讨论】:

    • 当我将此等待添加到代码中时,` WebDriverWait(driver, 20).until( EC.element_to_be_clickable((By.CSS_SELECTOR, "label[for='documentType-0']")) ).click()` 程序不会出错,但也不会单击按钮。屏幕上似乎没有发生任何事情。该程序只是继续到下一行。关于为什么它不会点击按钮的任何想法? @DebanjanB
    • @RyanBobber 查看答案更新并告诉我状态。
    • 使用执行脚本的更新有效!!非常感谢。我真的很感谢你的帮助。我还有一些问题需要解决,因此您可能会看到稍后发布的更多问题。
    • 我刚刚遇到了这个答案,谢谢@DebanjanB - 实际上已经为此工作了好几天。如此令人满意的修复
    • 点击使用ID,完美运行:WebDriverWait(self.driver, 5).until(EC.element_to_be_clickable((By.ID, pagination_div))).click()
    猜你喜欢
    • 2019-12-29
    • 1970-01-01
    • 2021-05-16
    • 2020-01-04
    • 2021-10-08
    • 2019-11-08
    • 2021-10-14
    • 2021-08-26
    • 2021-09-04
    相关资源
    最近更新 更多