Selenium 报错:element click intercepted: Element...is not clickable at point的解决办法

如果报错:element click intercepted: Element...is not clickable at point (x, y),出现错误可能有多种原因,可以尝试通过下面的方式解决:

1.由于存在JavaScript或AJAX调用,元素未被点击

尝试使用ActionsClass:

WebElement element = driver.findElement(By.id("shop-cart"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();

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

尝试使用JavascriptExecutor该元素在视口中:

WebElement element = driver.findElement(By.id("shop-cart"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].scrollIntoView()", element ); 

3.元素存在但具有永久叠加。

用于JavascriptExecutor直接在元素上发送单击。

WebElement element = driver.findElement(By.xpath("element_xpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);

你可能感兴趣的:(Selenium学习笔记)