javascript - ElementClickInterceptedException : Message: element click intercepted Element is not clickable error clicking a radio button using Selenium and Python

标签 javascript python selenium webdriver webdriverwait

我正在尝试单击第一个框(ASN/DSD)
enter image description here
但我收到此错误消息:

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>
关于如何停止点击被拦截的任何建议?

最佳答案

此错误消息...

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对于element_to_be_clickable()您可以使用以下任一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']"))))
    

  • 引用
    您可以在以下位置找到一些相关的讨论:
  • Element MyElement is not clickable at point (x, y)… Other element would receive the click
  • Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click
  • ElementClickInterceptedException: Message: element click intercepted: Element is not clickable with Selenium and Python
  • 关于javascript - ElementClickInterceptedException : Message: element click intercepted Element is not clickable error clicking a radio button using Selenium and Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62903056/

    相关文章:

    python - 设置 rect 后如何设置 pygame 矩形位置

    python - 如何在 QScintilla 中实现基于缩进的代码折叠?

    css - 如何在 Junit 框架中使用 seleniumRC 来动态改变 elementids

    javascript - 为什么我的 vue-router 链接偶尔会导致错误页面(或根本不起作用)?

    javascript - 如何定义将产生调用函数的完整调用的函数

    javascript - 在 jQuery 中使用 grep 编写通用过滤器

    python - 一台计算机上的 Bokeh 服务器,为另一台计算机服务

    javascript - 如何使用 JavaScript 显示 Facebook 评论?

    java - Selenium WebDriver - 使用 @FindBy 注释查找复选框的方法是什么?

    css - 如何单击代码段中存在部分文本的表记录 by.cssselector