Rya*_*ber 7 javascript python selenium webdriver webdriverwait
我正在尝试单击第一个框(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)
Run Code Online (Sandbox Code Playgroud)
我知道我已经输入了正确的 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()
Run Code Online (Sandbox Code Playgroud)
我看到 DebanjanB 在这里回答了类似的问题:链接
我正在尝试使用执行脚本来完成他的第三个解决方案。我不知道该模型使用什么 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']"))))
Run Code Online (Sandbox Code Playgroud)
我的问题是我需要在第一行使用什么 css 选择器,然后它只是我在第二行使用的初始 xpath 吗?
这是供参考的 HTML。当我尝试单击输入部分时,出现单击拦截错误。如果使用xpath点击label标签,不会报错,但也点击不到。它只是继续执行下一段代码而不执行任何操作。
<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>
Run Code Online (Sandbox Code Playgroud)
关于如何停止拦截点击有什么建议吗?
Deb*_*anB 20
这个错误信息...
\nselenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: \nElement <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"> \nis not clickable at point (338, 202). \nOther element would receive the click:\n <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>\nRun Code Online (Sandbox Code Playgroud)\n...意味着所需的元素不可单击,因为某些其他元素遮盖了它。
\n所需的元素是Angular元素,因此要调用click()该元素,您必须引发WebDriverWait ,并且element_to_be_clickable()可以使用以下任一定位器策略:
使用CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label[for=\'documentType-0\']"))).click()\nRun Code Online (Sandbox Code Playgroud)\n使用XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@for=\'documentType-0\']"))).click()\nRun Code Online (Sandbox Code Playgroud)\n注意:您必须添加以下导入:
\nfrom selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.common.by import By\nfrom selenium.webdriver.support import expected_conditions as EC\nRun Code Online (Sandbox Code Playgroud)\n作为替代方案,您可以使用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\']"))))\nRun Code Online (Sandbox Code Playgroud)\n使用XPATH:
driver.execute_script("arguments[0].click();", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@for=\'documentType-0\']"))))\nRun Code Online (Sandbox Code Playgroud)\n您可以在以下位置找到一些相关讨论:
\n| 归档时间: |
|
| 查看次数: |
51640 次 |
| 最近记录: |