Debugging “Element is not clickable at point” error

后端 未结 30 2580
余生分开走
余生分开走 2020-11-21 23:55

I see this only in Chrome.

The full error message reads:

\"org.openqa.selenium.WebDriverException: Element is not clickable at point (411, 675

30条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 00:14

    This might happen if the element changes position while the driver is attempting to click it (I've seen this with IE too). The driver retains the initial position but by the time it actually gets to clicking on it, that position is no longer pointing to that element. The FireFox driver doesn't have this problem BTW, apparently it "clicks" elements programmatically.

    Anyway, this can happen when you use animations or simply change the height of elements dynamically (e.g. $("#foo").height(500)). You need to make sure that you only click elements after their height has "settled". I ended up with code that looks like this (C# bindings):

    if (!(driver is FirefoxDriver))
    {
        new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(
            d => d.FindElement(By.Id(someDynamicDiv)).Size.Height > initialSize);
    }
    

    In case of an animation or any other factor you can't easily query for, you can utilize a "generic" method that waits for the element to be stationary:

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

提交回复
热议问题