Element ... is not clickable at point (x, y). Other element would receive theclick"可能是由于不同的因素造成的。您可以通过以下任一过程解决它们:
- 由于存在Javascript或AJAX调用而无法单击元素
尝试使用
ActionsClass:
WebElement element = driver.findElement(By.id("id1"));Actions actions = new Actions(driver);actions.moveToElement(element).click().build().perform();- 元素不在视口中,因此未获得点击
尝试用于
JavascriptExecutor将元素带入视口中:
JavascriptExecutor jse1 = (JavascriptExecutor)driver;jse1.executescript("scroll(250, 0)"); // if the element is on top.jse1.executescript("scroll(0, 250)"); // if the element is at bottom.要么
WebElement myelement = driver.findElement(By.id("id1"));JavascriptExecutor jse2 = (JavascriptExecutor)driver;jse2.executescript("arguments[0].scrollIntoView()", myelement);- 在元素可单击之前,页面正在刷新。
在这种情况下诱发一些
wait。
- 元素存在于DOM中,但不可单击。
在这种情况下
ExplicitWait,请为元素添加一些可单击的元素。
WebDriverWait wait2 = new WebDriverWait(driver, 10);wait2.until(ExpectedConditions.elementToBeClickable(By.id("id1")));- 存在元素,但具有临时覆盖。
在这种情况下, ExplicitWait
使用 ExpectedConditions
设置invisibilityOfElementLocated
为会使叠加层不可见。
WebDriverWait wait3 = new WebDriverWait(driver, 10);wait3.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("ele_to_inv")));- 存在元素,但具有永久覆盖。
用于
JavascriptExecutor直接在元素上发送点击。
WebElement ele = driver.findElement(By.xpath("element_xpath"));JavascriptExecutor executor = (JavascriptExecutor)driver;executor.executescript("arguments[0].click();", ele);


