问题描述
我只在 Chrome 中看到这一点.
I see this only in Chrome.
完整的错误信息如下:
"org.openqa.selenium.WebDriverException: 元素在点 (411, 675) 处不可点击.其他元素将收到点击:..."
将获得点击"的元素位于相关元素的一侧,而不是在它的顶部,也不与它重叠,也不会在页面上移动.
The element that 'would receive the click' is to the side of the element in question, not on top of it and not overlapping it, not moving around the page.
我尝试添加偏移量,但这也不起作用.该项目位于显示窗口中,无需滚动.
I have tried adding an offset, but that does not work either. The item is on the displayed window without any need for scrolling.
推荐答案
这是由以下3种类型引起的:
This is caused by following 3 types:
1.点击元素不可见.
使用 Actions 或 JavascriptExecutor 使其点击.
Use Actions or JavascriptExecutor for making it to click.
按操作:
WebElement element = driver.findElement(By("element_path"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().perform();
通过 JavascriptExecutor:
By JavascriptExecutor:
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(250, 0)"); // if the element is on top.
jse.executeScript("scroll(0, 250)"); // if the element is on bottom.
或
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].scrollIntoView()", Webelement);
然后点击元素.
2. 在点击元素之前页面正在刷新.
为此,让页面等待几秒钟.
For this, make the page to wait for few seconds.
3.该元素是可点击的,但它上面有一个微调器/叠加层
下面的代码将等到叠加层消失
The below code will wait until the overlay disppears
By loadingImage = By.id("loading image ID");
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));
然后点击元素.
这篇关于调试“元素在该点不可点击"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!