我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
当前回答
我也遇到了同样的问题,花了好几个小时才找到解决办法。我试着用量角器点击一个长ngGrid底部的单元格。这是我的ngrrid html的快照:
....many rows here..
<!- row in renderedRows ->
<!- column in renderedColumns ->
<div ...> <a ngclick="selectRow(row)"...>the test link 100000</a>...
....
所有的点击功能都不能工作。解决方案是在元素的当前范围内使用evaluate:
element(by.cssContainingText("a", "the test link 100000"))
.evaluate("selectRow(row)")
其他回答
在测试了所有提到的建议后,没有一个奏效。我写了这个代码。它有效,但并不漂亮
public void click(WebElement element) {
//https://code.google.com/p/selenium/issues/detail?id=2766 (fix)
while(true){
try{
element.click();
break;
}catch (Throwable e){
try {
Thread.sleep(200);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
public void click(String css) {
//https://code.google.com/p/selenium/issues/detail?id=2766 (fix)
while(true){
try{
driver.findElement(By.cssSelector(css)).click();
break;
}catch (Throwable e){
try {
Thread.sleep(200);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
而不是
webdriver.findElement(By.id("id1")).click();
试着使用
click(By.id("id1"));
void click(final By byLocator) {
waitFor(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
WebElement element = driver.findElement(byLocator);
if (element.isDisplayed()) {
try {
element.click();
return true;
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
@Override
public String toString() {
return "Element located " + byLocator + " clicked";
}
});
}
调试"元素在点上不可点击"错误
要处理此错误,请使用此代码向下滚动。
browser.execute_script("window.scrollTo(0, 300);")
Re Tony Lâmpada的回答,评论#27确实为我解决了这个问题,除了它提供了Java代码,而我需要Python。下面是一个Python函数,它滚动到元素的位置,然后单击它。
def scroll_to_and_click(xpath):
element = TestUtil.driver.find_element_by_xpath(xpath)
TestUtil.driver.execute_script('window.scrollTo(0, ' + str(element.location['y']) + ');')
element.click()
这解决了我在Chrome 34.0的问题。它在Firefox 28.0和IE 11中没有造成伤害;这些浏览器不受这个问题的影响,但在单击元素之前滚动到元素的位置仍然不是一件坏事。
当驱动程序试图点击元素时,如果元素改变了位置,就会发生这种情况(我在IE中也见过这种情况)。驱动程序保留初始位置,但当它真正点击它时,该位置不再指向该元素。顺便说一句,FireFox驱动程序没有这个问题,显然它是通过编程方式“点击”元素的。
无论如何,当你使用动画或简单地动态改变元素的高度(例如$("#foo").height(500))时,就会发生这种情况。你需要确保你只点击高度已经“确定”的元素。我最终得到了这样的代码(c#绑定):
if (!(driver is FirefoxDriver))
{
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(
d => d.FindElement(By.Id(someDynamicDiv)).Size.Height > initialSize);
}
在动画或任何其他你不容易查询的因素的情况下,你可以使用一个“通用”方法,等待元素是静止的:
var prevLocation = new Point(Int32.MinValue, Int32.MinValue);
int stationaryCount = 0;
int desiredStationarySamples = 6; //3 seconds in total since the default interval is 500ms
return new WebDriverWait(driver, timeout).Until(d =>
{
var e = driver.FindElement(By.Id(someId));
if (e.Location == prevLocation)
{
stationaryCount++;
return stationaryCount == desiredStationarySamples;
}
prevLocation = e.Location;
stationaryCount = 0;
return false;
});