錯誤Element is not clickable at point (x, y)
可能源於不同因素。您可以通過以下任一過程解決它們:
1.由於存在JavaScript或AJAX調用,元素未被點擊
嘗試使用Actions
Class:
WebElement element = driver.findElement(By.id("navigationPageButton"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
2.元素未被點擊,因為它不在視口內
嘗試使用JavascriptExecutor
該元素在視口中:
WebElement myelement = driver.findElement(By.id("navigationPageButton"));
JavascriptExecutor jse2 = (JavascriptExecutor)driver;
jse2.executeScript("arguments[0].scrollIntoView()", myelement);
3.在元素可點擊之前,頁面將被刷新。
在這種情況下,如第4點所述誘導ExplicitWait即WebDriverWait。
4.元素存在於DOM中但不可點擊。
在這種情況下, 請將ExplicitWaitExpectedConditions
設置elementToBeClickable
為可單擊的元素:
WebDriverWait wait2 = new WebDriverWait(driver, 10);
wait2.until(ExpectedConditions.elementToBeClickable(By.id("navigationPageButton")));
5.元素存在但具有臨時疊加。
在這種情況下,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);