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

完整的错误信息如下:

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

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

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


当前回答

我在python中运行selenium脚本时遇到了同样的问题。下面是我用来点击元素的:

from selenium.webdriver.common.action_chains import ActionChains


ActionChains(driver).click(element).perform()

其他回答

当驱动程序试图点击元素时,如果元素改变了位置,就会发生这种情况(我在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;
});

首先,尝试使用最新的Chrome驱动程序,并检查它是否解决了这个问题。

对我来说,这并没有解决问题。但是,到目前为止,下面的解决方案对我来说是有效的。以下是c#代码,但您可以在特定的语言中遵循相同的逻辑。我们要做的是,

步骤1:关注使用Selenium Actions对象的元素,

步骤2:然后点击元素

步骤3:如果有异常,那么我们通过Selenium浏览器驱动程序的“ExecuteScript”方法执行javascript脚本,从而触发元素上的javascript“Click”事件。

你也可以跳过步骤1和2,只尝试步骤3。步骤3本身就可以工作,但我注意到在一个场景中有一些奇怪的行为,在该场景中,尽管步骤3成功地单击了元素,但在单击元素后,在我的代码的其他部分导致了意想不到的行为。

            try
            {
                //Setup the driver and navigate to the web page...
                var driver = new ChromeDriver("folder path to the Chrome driver");
                driver.Navigate().GoToUrl("UrlToThePage");

                //Find the element...
                var element = driver.FindElement(By.Id("elementHtmlId")); 

                //Step 1
                new Actions(driver).MoveToElement(element).Perform();  

                //Step 2
                element.Click();
            }
            catch (Exception)
            {
                //Step 3
                driver.ExecuteScript("document.getElementById('elementHtmlId').click();");

            }

我有另一个bug,在Chrome和Poltergeist上的find_link无法单击一个带有EM标签和一些文本的A标签,尽管它在Firefox和rack_test中工作得很好。解决方案是将click_link(link)替换为:

find('a em', text: link).click

在我的例子中,它在Firefox中运行正常,但在Chrome中失败了。在Chrome中,在更新Chrome驱动程序版本到最新版本后,该问题得到了修复。

ruby / watir-webdriver /铬

我用了下面的技巧,看起来很管用:

#scroll to myelement
@browser.execute_script "window.scrollTo(#{myelement.element.wd.location[0]},#{myelement.element.wd.location[1]})"

# click myelement
myelement.when_present.fire_event("click")