我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
我只在Chrome浏览器中看到这个。
完整的错误信息如下:
“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”
“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。
我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。
当前回答
我有另一个bug,在Chrome和Poltergeist上的find_link无法单击一个带有EM标签和一些文本的A标签,尽管它在Firefox和rack_test中工作得很好。解决方案是将click_link(link)替换为:
find('a em', text: link).click
其他回答
当使用量角器时,这帮助了我:
var elm = element(by.css('.your-css-class'));
browser.executeScript("arguments[0].scrollIntoView();", elm.getWebElement());
elm.click();
在Drupal中使用Selenium时:
// Get element.
$element = $this->driver->getElement('xpath=//input');
// Get screen location.
$location = $element->getLocation();
// To make sure that Chrome correctly handles clicking on the elements
// outside of the screen, we must move the cursor to the element's location.
$this->driver->moveCursor($location['x'], $location['y']);
// Optionally, set some sleep time (0.5 sec in the example below) if your
// elements are visible after some animation.
time_nanosleep(0, 500000000);
// Click on the element.
$element->click();
我有同样的问题,尝试了所有提供的解决方案,但它们都不适合我。 最后我用了这个:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("var evt = document.createEvent('MouseEvents');" + "evt.initMouseEvent('click',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);" + "arguments[0].dispatchEvent(evt);", findElement(element));
希望这能有所帮助
错误信息解释:
错误消息只是说,您想要单击的元素存在,但它不可见。它可能被什么东西覆盖,或者暂时看不见。
元素在测试时不可见的原因有很多。请重新分析您的页面,并为您的情况找到合适的解决方案。
特殊情况的解决方案:
在我的例子中,当我刚刚点击的屏幕元素的工具提示出现在我想要点击的下一步元素上时,就发生了这个错误。离焦是我需要的解决方案。
快速解决散焦的方法是点击屏幕另一部分的其他元素,这些元素“没有”反应。点击动作后什么都不会发生。 正确的解决方案是在弹出工具提示的元素上调用element.blur(),这将使工具提示消失。
我做了一种蛮力点击,它对我有用。
try:
elem.click()
except:
print "failed to click"
size = elem.size
mid_of_y = int(size["height"])/2
stepts_to_do_to_left = int(size["width"])
while stepts_to_do_to_left > 0:
try:
print stepts_to_do_to_left, mid_of_y
action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element_with_offset(elem, mid_of_y, stepts_to_do_to_left)
action.click()
action.perform()
print "DONE CLICK"
break
except:
pass