尝试单击复选框时出现"Element click intercepted"错误



我想在加载页面后点击复选框,但我收到以下错误消息:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <img class="checkboximage" src="/images/nav/ns_x.gif" alt=""> is not clickable at point (843, 7). Other element would receive the click: <a class="ns-help" onclick="nlPopupHelp('EDIT_TRAN_CUSTINVC');" tabindex="0" onkeypress="(event.keyCode == 13 || event.charCode == 32) &amp;&amp; nlPopupHelp('EDIT_TRAN_CUSTINVC');">...</a>

这就是我现在所拥有的:在这个之前,我已经尝试了其他几种方法

collectionsbox = driver.find_element(By.CSS_SELECTOR,"#custbody_in_collections_fs_inp")
driver.execute_script("arguments[0].scrollIntoView(true)", collectionsbox)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@id='custbody_in_collections_fs']//img[@class='checkboximage']"))).click()
collectionsbox.click() #USUALLY FAILS RIGHT HERE
savebutton = driver.find_element(By.XPATH,"//input[@id='btn_multibutton_submitter']")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='btn_multibutton_submitter']"))).click()
driver.execute_script("arguments[0].scrollIntoView(true)", savebutton)
savebutton.click()
time.sleep(2)
driver.switch_to.alert.accept()

我已经尝试了EC方法,等待了几秒钟,向下滚动查看元素。我甚至使用过Xpath、ID和CSS。

<input onclick="setEventCancelBubble(event); this.isvalid=(nlapiValidateField(null,'custbody_in_collections')); if (this.isvalid) {setWindowChanged(window, true);nlapiFieldChanged(null,'custbody_in_collections');;} else if ( window.loadcomplete &amp;&amp; !document.page_is_resetting ) {setFormValue(this, !this.checked);}" aria-labelledby="custbody_in_collections_fs_lbl" onchange="NLCheckboxOnChange(this); " onkeypress="NLCheckboxOnKeyPress(event);  return true;" name="custbody_in_collections" id="custbody_in_collections_fs_inp" type="checkbox" value="T" class="checkbox" style="">
<input type="hidden" name="custbody_in_collections_send" style="">
<img class="checkboximage" src="/images/nav/ns_x.gif" alt="" style="">

我只需要单击复选框,然后单击顶部的"保存"。

似乎DOM上的另一个元素无意中隐藏了您试图单击的元素。您可以尝试执行Javascript进行点击。这通常能解决我的问题。

代替collectionsbox.click() #USUALLY FAILS RIGHT HERE,您可以替换为:

driver.execute_script("arguments[0].click();", collectionsbox)

To address元素在点(x,y(错误时不可点击。我们可以按照以下方法来解决这个问题

解决方案

1.行动类

WebElement element = driver.findElement(By.id("yourelement ID"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();

2.元素未被点击,因为它不在Viewport内

使用JavascriptExecutor获取Viewport中的元素:

checkBox=WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"yourelement Xpath")))
ActionChains(driver).move_to_element(checkBox).click(checkBox).perform()

最新更新