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

完整的错误信息如下:

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

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

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


当前回答

这是由以下3种类型引起的:

1.单击该元素是不可见的。

使用Actions或JavascriptExecutor让它点击。

行动:

WebElement element = driver.findElement(By("element_path"));

Actions actions = new Actions(driver);

actions.moveToElement(element).click().perform();

由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.

or

JavascriptExecutor jse = (JavascriptExecutor)driver;

jse.executeScript("arguments[0].scrollIntoView()", Webelement); 

然后单击元素。

2.在单击元素之前,页面会被刷新。

为此,让页面等待几秒钟。

3.元素是可点击的,但有一个旋转/覆盖在它的顶部

下面的代码将等待覆盖消失

By loadingImage = By.id("loading image ID");

WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);

wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));

然后单击元素。

其他回答

如果你试图点击一个被禁用的输入或按钮,这种情况也会发生,在这种情况下,元素没有重叠,但它是不可点击的。

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

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

我也因为同样的原因被卡了两天,实际上滚动会让它工作,因为可能是数据无法正常加载,这可能会导致同样的错误一次又一次。

我所做的是,我随机向下滚动,一次是(0,-500),然后是(0,400),然后是(0.-600),你可以根据你的使用给出这些滚动值。只要滚动它,你有内容点击。

driver.execute_script("scrollBy(0,-500);")
sleep(5)

driver.execute_script("scrollBy(0,400);")
sleep(5)

driver.execute_script("scrollBy(0,-600);")
sleep(5)

这真的很有效:)

今天我遇到了同样的问题。如果我说我是如何解决问题的,你不会相信我。

通过最大化浏览器大小

是的,这是一个指针问题,意味着浏览器的大小。为此,您只需要手动或通过代码最大化窗口大小。