错误Element is not clickable at point (x, y)
可能源于不一样因素。您能够经过如下任一过程解决它们:css
1.因为存在JavaScript或AJAX调用,元素未被点击ui
尝试使用Actions
Class:url
WebElement element = driver.findElement(By.id("navigationPageButton")); Actions actions = new Actions(driver); actions.moveToElement(element).click().build().perform();
2.元素未被点击,由于它不在视口内spa
尝试使用JavascriptExecutor
该元素在视口中:.net
WebElement myelement = driver.findElement(By.id("navigationPageButton")); JavascriptExecutor jse2 = (JavascriptExecutor)driver; jse2.executeScript("arguments[0].scrollIntoView()", myelement);
3.在元素可点击以前,页面将被刷新。code
在这种状况下,如第4点所述诱导ExplicitWait即WebDriverWait。orm
4.元素存在于DOM中但不可点击。ip
在这种状况下, 请将ExplicitWaitExpectedConditions
设置elementToBeClickable
为可单击的元素:ci
WebDriverWait wait2 = new WebDriverWait(driver, 10); wait2.until(ExpectedConditions.elementToBeClickable(By.id("navigationPageButton")));
5.元素存在但具备临时叠加。element
在这种状况下,ExplicitWait
使用 ExpectedConditions
set设置invisibilityOfElementLocated
为Overlay是不可见的。
WebDriverWait wait3 = new WebDriverWait(driver, 10); wait3.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("ele_to_inv")));
6.元素存在但具备永久叠加。
用于JavascriptExecutor
直接在元素上发送单击。
WebElement ele = driver.findElement(By.xpath("element_xpath")); JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].click();", ele);