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

完整的错误信息如下:

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

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

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


当前回答

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.<Id or anything>));

希望这能有所帮助。

其他回答

在Visual Studio 2013中,如果你启用BrowserLink -它会在屏幕底部显示一个BrowserLink导航栏。如果你想点击的项目在导航栏后面,它会给出错误。禁用BrowserLink为我解决了这个问题。

显然,这是Chrome驱动二进制文件中“不会修复”错误的结果。

一个对我有效的解决方案(我们的里程可能有所不同)可以在这个谷歌小组讨论中找到,评论#3:

https://groups.google.com/forum/?fromgroups= !主题/ selenium-developer-activity / DsZ5wFN52tc

相关的部分在这里:

从那以后,我通过直接导航到的href来解决这个问题 跨度的父锚。 driver.Navigate () .GoToUrl (driver.FindElement (By.Id (embeddedSpanIdToClick)) .FindElement (By.XPath(“。”)).GetAttribute(“href”));

在我的例子中,我使用的是Python,所以一旦我得到了所需的元素,我就简单地使用

driver.get(ViewElm.get_attribute('href'))

我希望这只工作,但是,如果你试图点击的元素是一个链接…

我也遇到了同样的问题,这是由div和div内链接之间的id冲突引起的。所以驱动程序点击了div而不是我想要的链接。 我改变了div id,它正常工作。

之前:

<div id="logout"><a id="logout" href="logoutLink">logout</a></div>

后:

<div id="differentId"><a id="logout" href="logoutLink">logout</a></div>

这是由以下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));

然后单击元素。

而不是

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";
        }
    });
}