問題描述
我正在嘗試單擊第一個框(ASN/DSD)
I am trying to click on the first box (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,因為它可以找到元素,而不是點擊它.我的代碼是
I know I have entered the right iframe because it can find the element, just not click on it. My code is
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 在這里回答了類似的問題:鏈接
I saw that DebanjanB answered a similar question on here: link
我正在嘗試使用執行腳本的第三個解決方案.我不知道該模型使用什么 CSS 選擇器.模型是這樣的
I am trying to do his third solution of using execute script. I don't know what CSS selector to use for this model. The model looks like this
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?
My question is what css selector do I need to use on the first line, and then is it just initial xpath I was using on the second line?
這是供參考的 HTML.當我嘗試點擊輸入部分時,我收到點擊攔截錯誤.如果使用xpath點擊標簽標簽,它不會出錯但也不會點擊它.它只是移動到下一段代碼而不做任何事情.
Here is the HTML for reference. I get the click intercept error when I try to click on the input section. If use xpath to click on the label tag, it does not error out but also does not click on it. It just moves on to the next section of code without doing anything.
<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>
關于如何停止點擊被攔截的任何建議?
Any suggestions on how to stop having the click intercepted?
推薦答案
這個錯誤信息...
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>
...暗示所需元素不可點擊,因為某些其他元素會遮擋它.
...implies that the desired element wasn't clickable as some other element obscures it.
所需的元素是 Angular 元素,以便在元素上調用 click()
您必須為 element_to_be_clickable()
并且您可以使用以下任一定位器策略:
The desired element is a Angular element so to invoke click()
on the element you have to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following 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()
注意:您必須添加以下導入:
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
您也可以使用 execute_script()
方法,如下所示:
As an alternative you can use the execute_script()
method as follows:
使用
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']"))))
您可以在以下位置找到一些相關討論:
You can find a couple of relevant discussions in:
- 元素MyElement 在 (x, y) 點不可點擊……其他元素會收到點擊
- Selenium Web 驅動程序和爪哇.元素在點 (x, y) 處不可點擊.其他元素會收到點擊
- ElementClickInterceptedException:消息:元素點擊被攔截:元素不是可通過 Selenium 和 Python 進行點擊
這篇關于ElementClickInterceptedException:消息:元素單擊被攔截元素不可點擊錯誤單擊使用 Selenium 和 Python 的單選按鈕的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!