我只在Chrome浏览器中看到这个。

完整的错误信息如下:

“org.openqa.selenium。WebDriverException:元素在点(411,675)不可点击。其他元素会收到点击:……”

“将接收点击”的元素位于相关元素的一侧,而不是在元素的顶部,也没有重叠,也没有在页面上移动。

我试过加一个偏移量,但也不行。该项目在显示的窗口上,不需要滚动。


当前回答

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中没有造成伤害;这些浏览器不受这个问题的影响,但在单击元素之前滚动到元素的位置仍然不是一件坏事。

其他回答

在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();

我得到这个bug是因为我测试了一个悬停,然后需要点击工具提示下面的链接。解决方案是添加page.find('.sp-logo')。鼠标悬停在click_link之前以获得工具提示。

您需要在该元素上使用焦点或滚动。您可能还必须使用显式等待。

WebElement firstbutton= driver.findElement(By.xpath("Your Element"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.perform();

OR

元素是不可点击的,因为它上面有一个旋转/覆盖:

By loadingImage = By.id("loading image ID");
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));

OR

Point p= element.getLocation();
Actions actions = new Actions(driver);
actions.moveToElement(element).movebyoffset(p.x,p.y).click().perform();

OR

如果仍然不能工作,请使用JavascriptExecutor

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", firstbutton);

我在使用xvfb-run运行测试时遇到此错误。他们在当地工作得完美无缺。使用chrome, webdriver / chromedriver / chrome / java等版本都相同。

在chromedriver - GitHub Link中,“不会修复”的bug由Tony Lâmpada指出,这可能与屏幕上可见/不可见的内容有关。

xvfb-run的帮助信息如下所示:

-s ARGS   --server-args=ARGS    arguments (other than server number and
                                "-nolisten tcp") to pass to the Xvfb server
                                (default: "-screen 0 640x480x8")

更改xvfb的分辨率可以消除错误:

xvfb-run -s "-screen 0 1280x1024x16" ...

如果您在一个模式(弹出式)中遇到这个问题,请注意,可能是在当前顶级模式下存在另一个具有相同属性的元素。这抓住了我,只是增加你的选择器的特异性,以减少范围的模式,你只是试图点击。