Debugging “Element is not clickable at point” error

后端 未结 30 2137
余生分开走
余生分开走 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;
    });
    
    0 讨论(0)
  • 2020-11-22 00:15

    Apparently this is the result of a "Won't Fix" bug in the Chrome driver binary.

    One solution that worked for me (Our Mileage May Vary) can be found in this Google Group discussion, Comment #3:

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

    The relevant portion is right here:

    I've since worked around the issue by navigating directly to the href of the parent anchor of the span.

    driver.Navigate().GoToUrl(driver.FindElement(By.Id(embeddedSpanIdToClick)).FindElement(By.XPath("..")).GetAttribute("href"));

    In my case, I'm using Python, so once I got the desired element, I simply used

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

    I would expect this to only work, however, if the element you are trying to click on is a link...

    0 讨论(0)
  • 2020-11-22 00:15

    I was also stuck for two days because of the same reason, actually Scrolling will make it work, because may be the data couldn't load properly, which may cause the same error again and again.

    What I did is, I scroll down randomly, once with (0,-500), then (0,400), then (0.-600), you may give these scroll value according to your use. Just scroll it where you have the content to click.

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

    It really worked :)

    0 讨论(0)
  • 2020-11-22 00:15

    I had the same problem and it was caused by an id conflict between the div and the link inside the div. So driver was clicking on the div instead of the link that I wanted. I changed the div id and it worked properly.

    Before:

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

    After:

    <div id="differentId"><a id="logout" href="logoutLink">logout</a></div>
    
    0 讨论(0)
  • 2020-11-22 00:17

    I was getting the same issue while running selenium script in python. Here is what I used to click on the element:

    from selenium.webdriver.common.action_chains import ActionChains
    
    
    ActionChains(driver).click(element).perform()
    
    0 讨论(0)
  • 2020-11-22 00:18

    ruby/watir-webdriver/chrome

    I use the following trick and seems like it works:

    #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")
    
    0 讨论(0)
提交回复
热议问题