474

I see this only in Chrome.

The full error message reads:

"org.openqa.selenium.WebDriverException: Element is not clickable at point (411, 675). Other element would receive the click: ..."

The element that 'would receive the click' is to the side of the element in question, not on top of it and not overlapping it, not moving around the page.

I have tried adding an offset, but that does not work either. The item is on the displayed window without any need for scrolling.

Max Voitko
  • 1,542
  • 1
  • 17
  • 32
user1591169
  • 4,741
  • 3
  • 14
  • 3
  • 3
    Do you wait for page to load? Maybe other element overlap it while the page is loading? – Herokiller Aug 13 '12 at 05:27
  • 67
    Long story short for those just arriving - THE ELEMENT IS NOT VISIBLE ON THE PAGE AND THEREFORE IS NOT CLICKABLE. YOU NEED TO SCROLL THE VIEWPORT BY EMITTING window.ScrollTo. – Chris B. Behrens Apr 16 '14 at 16:02
  • 74
    @ChrisB.Behrens This isn't always the case. This particular error can also be given when an element is covered by another. I had this exception when trying to click a button that was being another element with postion fixed. – Martin Cassidy Jun 13 '14 at 12:56
  • I get this error when a temporary element *partially* over shadows the click-able item for a tiny amount of time (less then a second). – Ben George Feb 08 '16 at 22:40
  • 1
    Seems to be only Chromedriver also. The implicit wait should solve this problem in theory. – Ben George Feb 08 '16 at 22:41
  • 4
    Its not only Chromedriver- had the same problem with Firefox. I fixed the problem by implementing a delay to wait till the page has fully reloaded, as suggested by others above. – codervince Mar 13 '16 at 02:47
  • 8
    I think this is absolutely wrong advice to emit scrollTo or make any waits. Looks like the algorithm of selenium click is: 1. calculate element position 2. scrollTo this position (so you don't need to issue it yourself) 3. click to this position (exception comes from last assertion which checks what element stands on this position just before actual click event sending) My advices are: 1. check if element is inside your viewport. 2. check if element is covered by any other (like sticky menus), hide them if there are any, or scroll manually before click without relying on builtin scrollTo. – Vitalik Verhovodov Mar 18 '16 at 12:19
  • 1
    For the same error in Firefox, see http://stackoverflow.com/questions/36730855/selenium-element-is-not-clickable-at-point-error-in-firefox/ – emery Apr 19 '16 at 22:59
  • Even if the webelement is not visible on screen findElement() can find it and click on it. – a Learner Jan 10 '22 at 19:23
  • in my case I was using codeception with php, and since the element was not visible on that moment I had to use `$this->tester->executeJS("jQuery('#publish').click()");`. instead of `$this->tester->click(['id' => 'publish']);` – Rubislandy Rodriguez Mar 04 '22 at 18:45

52 Answers52

384

This is caused by following 3 types:

1. The element is not visible to click.

Use Actions or JavascriptExecutor for making it to click.

By Actions:

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

Actions actions = new Actions(driver);

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

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

Then click on the element.

2. The page is getting refreshed before it is clicking the element.

For this, make the page to wait for few seconds.

3. The element is clickable but there is a spinner/overlay on top of it

The below code will wait until the overlay disppears

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

WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);

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

Then click on the element.

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Prabu Ananthakrishnan
  • 4,139
  • 1
  • 12
  • 16
  • 62
    There is a third type of cause, which is that your element is wrapped in a div or a span. The page can be fully loaded, and completely within the viewport, but Chromedriver will refuse to click it, where the webdriver for FF and IE have no issue. A real human has no clue that the span exists, and the browser doesn't care when you actually click it, as a human. Neither moving around, nor waiting will solve this issue; either avoid Chrome/chromedriver, or rewrite the page's HTML seem to be the only options for people in case 3. – Don Simon May 21 '15 at 16:32
  • 62
    @DonSimon I had the same issue that you did. I was able to get around it by using .SendKeys(Keys.Return) instead of .Click. This worked for me in Chrome where I was having this issue and in Firefox where I was having another similar issue on this particular link (anchor wrapped in a Div). – Peter Bernier Jul 08 '15 at 18:47
  • 23
    The solution suggested by @PeterBernier works well in the case where the element is wrapped in a div or a span. In Python I used .send_keys('\n') to simulate the click and work around the issue in Chrome. – G-J Feb 16 '16 at 18:07
  • 4
    If an element is hidden by a div element the following code fixes it. executeJavascript("arguments[0].click();", selenium.findElement(locator)); – Aaron Levenstein Jul 13 '16 at 16:14
  • You can also wait for the element to be clickable. wait.Until(ExpectedConditions.ElementToBeClickable(webElement)); – Chielus Nov 28 '16 at 07:22
  • I tried `Action` and `JavascriptExecutor`, neither worked, but @PeterBernier solution worked for me, using `send_keys('\n') will click the button, not sure why though... – Kevin Zhao Jan 07 '17 at 02:00
  • @PeterBernier's solution works for me. In my particular case, it seems that when Bootstrap is used to wrap a drop-down caret in a span, if the button only contains a caret, Selenium will not click on it. Sending a return key instead does work. – BnMcG Jan 27 '17 at 11:29
  • In my case I needed to send a space key: SendKeys(Keys.Space) – Alex Che Aug 19 '18 at 21:45
  • "ExpectedConditions.elementToBeClickable" with WebDriverWait works best in these cases. This will work if you are facing the isssue where webdriver is waiting too long. WebDriverWait wait = new WebDriverWait(driver, 5); WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid"))); – tigersagar Nov 12 '18 at 09:31
  • OMG There's a 4th reason! Chrome has a bug in it if you use the `zoom` CSS attribute. See more here: https://stackoverflow.com/questions/57693523/element-is-not-clickable-at-point-has-the-wrong-co-ordinates/57693524#57693524 – Ryan Shillington Aug 28 '19 at 13:24
  • "ExpectedConditions.elementToBeClickable" returns true for me under which `element.click()` will still throw the "element is not clickable" error - in this case, there is a translucent div overtop the element – 1800 INFORMATION Dec 05 '19 at 01:01
  • Using the Actions class did it for me.. thanks a lot, stuck with the same problem for 2 days.. – Lazar Zoltan Aug 11 '20 at 20:48
  • I successfully avoid it by using wait.until(EC.element_to_be_clickable()) in many cases. – vitaliis Nov 24 '20 at 03:01
  • Found another cause: the page actually uses the same #id for two elements. The first element is unclickable. The second (desired) element is. But the find by id comes back with the first. – scorpdaddy Nov 18 '21 at 23:18
  • @G-J Thanks for saving my day, I had this issue for mobile browser Chrome on Android while the test was working fine on other browsers. I changed the click to settingsPage.sendKeys('@searchRegionField', browser.Keys.ENTER); and it worked like a charm on both. Thank you so much! :) – Mujtaba Mehdi Mar 03 '23 at 13:20
  • 1
    @PeterBernier answer is working like a charm in C#, SendKeys is perfect when the element is wrapped by DIV in my case. Thanks! – gatsby Aug 31 '23 at 06:29
90

You can also use JavaScript click and scrolling would be not required then.

IJavaScriptExecutor ex = (IJavaScriptExecutor)Driver;
ex.ExecuteScript("arguments[0].click();", elementToClick);
Liam
  • 27,717
  • 28
  • 128
  • 190
Bart Wojtala
  • 1,290
  • 9
  • 7
  • 7
    Unbelievable! I wonder why selenium does not trash the click() method that they provide, given that there are conditions in which isDisplayed() and isEnabled() are not enough to click on an element, and this seems the only one solution. Thanks! – Giovanni Bitliner Aug 20 '17 at 17:50
  • 3
    +1: This is the solution that worked for me. `actions.MoveToElement` didn't work for me in C# and the other scrolling solutions seemed a little fragile in that there was a chance the scrolling might not correctly get the element into view or the element's position on the page could change. – User Oct 01 '17 at 05:32
  • 3
    this solution is the easiest if the element is not in view, but exists on the page – Yashveer Rana Oct 06 '17 at 06:39
  • @Giovanni Bitliner They do not provide this method since it is not a real user scenario. Users should also have to wait till the loader disappears. I think thats a wonderfull thing about selenium. – Gideon Mulder Oct 30 '17 at 08:41
  • +1 Also worked for me. Just made added flwg method to my code: ` private void jsClick(IWebElement element, IWebDriver driver) { IJavaScriptExecutor ex = (IJavaScriptExecutor)driver; ex.ExecuteScript("arguments[0].click();", element); } ` invoked this way: 'jsClick(driver.FindElement(By.XPath("xpathOfTheElement"))); ` – Jeremias Nov 17 '17 at 11:28
  • Yes, this is working for me. Also, You can use scrollIntoView() then click() for default effect.. – Dharmang Mar 14 '18 at 13:30
  • Having tried most of the above solutions to no avail, but this definitely worked for me (Selenium-3.12.0, Cucumber stack for Chrome Driver) – vijay pujar Jun 06 '18 at 09:08
  • Thanks man ! that was efficient,I have put it as B plan : try { webElement.click(); } catch(WebDriverException ex){ ((JavascriptExecutor) driver).executeScript("arguments[0].click();", webElement); } – Shessuky Nov 02 '19 at 16:35
50

There seems to be a bug in chromedriver for that (the problem is that it's marked as won't fix) --> GitHub Link

(place a bounty on FreedomSponsors perhaps?)

There's a workaround suggested at comment #27. Maybe it'll work for you-

John Smith
  • 7,243
  • 6
  • 49
  • 61
Tony Lâmpada
  • 5,301
  • 6
  • 38
  • 50
  • 5
    Seems fair - if the button isn't on the screen then it isn't really clickable. – Evan Knowles Oct 17 '13 at 08:19
  • 1
    This is not a bug. This is intended behaviour and it is correct. As other suggested, if element is outside of viewport - you need to scroll to it. – Alex Skrypnyk May 06 '15 at 06:10
  • I tried Firefox and found it did not give this error, yet the click was still ignored. It turned out to be the a parent div had a height of zero. Once that was fixed both worked fine. – dansalmo Jun 28 '17 at 21:13
  • There I found this method that solved it for me (on Chrome) self.browser.execute_script("arguments[0].click();", item) – Martin Garcia Aug 23 '20 at 04:56
39

I had the same issue, tried all offered solutions but they did not work for me. eventually I used this:

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("var evt = document.createEvent('MouseEvents');" + "evt.initMouseEvent('click',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);" + "arguments[0].dispatchEvent(evt);", findElement(element));

Hope this helps

Liam
  • 27,717
  • 28
  • 128
  • 190
XGillerX
  • 491
  • 4
  • 3
24

Wow, a lot of answers here, and many good ones.

I hope I'll add something to this from my experience.

Well guys, in my case there was a cookie overlay hiding the element occasionally. Scrolling to the element also works; but in my humble opinion (for my case, not a panacea for everyone) the simplest solution is just to go full screen (I was running my scripts on a 3/4 of the screen window)! So here we go:

driver.manage().window().maximize();

Hope that helps!

Xwris Stoixeia
  • 1,831
  • 21
  • 22
  • Worked for me too but unfortunately, Chrome is still not finding the element sometimes. – Alam Mar 08 '21 at 00:43
20

You need to use focus or scroll on that element. You also might have to use explict wait.

WebElement firstbutton= driver.findElement(By.xpath("Your Element"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.perform();

OR

The element is not clickable because of a Spinner/Overlay on top of it:

By loadingImage = By.id("loading image ID");
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));

OR

Point p= element.getLocation();
Actions actions = new Actions(driver);
actions.moveToElement(element).movebyoffset(p.x,p.y).click().perform();

OR

If still not work use JavascriptExecutor

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", firstbutton);
Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
15

I have seen this in the situation when the selenium driven Chrome window was opened too small. The element to be clicked on was out of the viewport and therefore it was failing.

That sounds logical... real user would have to either resize the window or scroll so that it is possible to see the element and in fact click on it.

After instructing the selenium driver to set the window size appropriately this issues went away for me. The webdriver API is decribed here.

opichals
  • 313
  • 2
  • 6
13

I, too, wrestled with this problem. Code works fine in FF, fails on Chrome. What I was trying to do was to click a tickbox - if it wasn't in view, I'd scroll to view and then click. Even scrolling into view works in Chrome, only the bottom few pixels of the tickbox wasn't visible so webdriver refused to click on it.

My workaround is this:

WebElement element = _sectorPopup.findElement(...);

((Locatable) element).getCoordinates().inViewPort();
try {
    element.click();
} catch (Exception e) {
    new Actions(getWebDriver()).sendKeys(Keys.PAGE_DOWN).perform();
    element.click();
}

Chrome also has issues with sendKeys, using Actions is sometimes necessary. Obviously, you need to know which direction and how much you need to go so your mileage may vary. But I prefer this to the javascript hack, so I'm posting it here in case someone else will find it useful.

Liam
  • 27,717
  • 28
  • 128
  • 190
kolibri
  • 131
  • 1
  • 5
13

I was getting this error when running tests headless with xvfb-run. They were working flawlessly locally. Using chrome, versions of webdriver / chromedriver / chrome / java etc all identical.

The ‘won’t fix’ bug in chromedriver - GitHub Link pointed out by Tony Lâmpada suggested this may be related to what is / isn't visible on the screen.

Help message for xvfb-run shows the following:

-s ARGS   --server-args=ARGS    arguments (other than server number and
                                "-nolisten tcp") to pass to the Xvfb server
                                (default: "-screen 0 640x480x8")

Changing the resolution for xvfb made the error go away:

xvfb-run -s "-screen 0 1280x1024x16" ...
John Smith
  • 7,243
  • 6
  • 49
  • 61
u-phoria
  • 364
  • 4
  • 13
12

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")
Annet
  • 673
  • 1
  • 7
  • 17
  • 1
    The issue I was seeing was with an area map. The error was the same as the original post here - a div "in front of" the area I needed to click. It was not an AJAX/timing/page load issue, and the area was in full view - I could not even scroll to focus on it. However, changing my click method from object.click to object.fire_event("click") seems to have resolved the issue for me. I left it in a begin/rescue block so that it would not possibly affect how Firefox is clicking normally. – adam reed Jun 28 '13 at 17:04
  • This approach worked around the issue for me when there were elements not visible in the viewport. – Jason R. Coombs Apr 24 '18 at 01:07
10

First, try to get the latest Chrome driver and check if it solves the issue.

In my case, it didn't fix the issue. But, the following solution worked for me so far. The following is C# code but you can follow same logic in your specific language. What we do here is,

Step 1: Focus on the element using the Selenium Actions object,

Step 2: Then do a click on the element

Step 3: If there's an exception, then we trigger a javascript "Click" event on the element by executing the javascript script through the Selenium browser driver's "ExecuteScript" method.

You can also skip step 1 and 2 and try only step 3 too. Step 3 would work on it's own but I noticed some strange behavior in one scenario in which step 3, even though it successfully clicked the element, caused unexpected behavior in other parts of my code after clicking the element.

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

            }
Sujeewa
  • 711
  • 8
  • 10
10

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()
psr
  • 2,619
  • 4
  • 32
  • 57
9

When using Protractor this helped me:

var elm = element(by.css('.your-css-class'));
browser.executeScript("arguments[0].scrollIntoView();", elm.getWebElement());
elm.click();
Gal Bracha
  • 19,004
  • 11
  • 72
  • 86
7

I made this method based on a comment from Tony Lâmpada's answer. It works very well.

def scroll_to(element)
  page.execute_script("window.scrollTo(#{element.native.location.x}, #{element.native.location.y})")
end
Roger Garza
  • 1,493
  • 1
  • 12
  • 11
5

Today I got the same kind of issue. You don't believe me if i say how i solved the issue.

By maximizing the browser size

Yes, it is a pointer issue that means the size of the browser. For that, you just need to maximize the window size manually or through the code.

Sindhukumari P
  • 324
  • 2
  • 6
4

I was facing a similar problem whre i have to check two check boxes one after the other.But i was getting the same above error.hence i added wait in between my steps for checking the checkboxes....its working fine and great.here are the steps:-

  When I visit /administrator/user_profiles
  And I press xpath link "//*[@id='1']"
  Then I should see "Please wait for a moment..."
  When I wait for 5 seconds
  And I press xpath link "//*[@id='2']"
  Then I should see "Please wait for a moment..."
  When I visit /administrator/user_profiles_updates
Milind
  • 4,535
  • 2
  • 26
  • 58
  • Just adding that this is not the proper way to use Gherkin syntax. Steps should be in the form "given - when - then" and these should not be mixed. If more "whens" are needed after a "then", probably a separate test case is needed. – Floella Aug 20 '19 at 18:03
4

The reason for this error is that the element that you are trying to click is not in the viewport (region seen by the user) of the browser. So the way to overcome this is by scrolling to the desired element first and then performing the click.

Javascript:

async scrollTo (webElement) {
    await this.driver.executeScript('arguments[0].scrollIntoView(true)', webElement)
    await this.driver.executeScript('window.scrollBy(0,-150)')
}

Java:

public void scrollTo (WebElement e) {
    JavascriptExecutor js = (JavascriptExecutor) driver; 
    js.executeAsyncScript('arguments[0].scrollIntoView(true)', e)
    js.executeAsyncScript('window.scrollBy(0,-150)')
}
sri
  • 801
  • 9
  • 10
3

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

Community
  • 1
  • 1
alpheus
  • 317
  • 3
  • 3
3

Re Tony Lâmpada's answer, comment #27 did indeed solve the problem for me, except that it provided Java code and I needed Python. Here's a Python function that scrolls to the element's position and then clicks it.

def scroll_to_and_click(xpath):
    element = TestUtil.driver.find_element_by_xpath(xpath)
    TestUtil.driver.execute_script('window.scrollTo(0, ' + str(element.location['y']) + ');')
    element.click()

This solved the problem for me in Chrome 34.0. It caused no harm in Firefox 28.0 and IE 11; those browsers aren't subject to the problem, but scrolling to the element's position before clicking it still isn't a bad thing.

Steve Saporta
  • 4,581
  • 3
  • 30
  • 32
3

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;
});
Ohad Schneider
  • 36,600
  • 15
  • 168
  • 198
  • This appears to be what I'm experiencing. I intermittently get the OP's "Other Element would..." exception, but screenshots show the modal is on the screen and element is not covered and I use waits before clicking. Turns out when the modal I'm clicking opens it actually slides down the page. Depending on when the selenium wait actual samples the DOM, the exception can be thrown if it caught the modal as it was moving. – Levi Noecker Sep 16 '16 at 12:50
3

I met this because a loading dialog cover on this element. I simplely solve it by add a waiting before working with the this element.

try {
        Thread.sleep((int) (3000));
    } catch (InterruptedException e) {
        //
        e.printStackTrace();
    }

Hope this help!

Huy Hóm Hỉnh
  • 597
  • 7
  • 18
3

Explanation of error message:

The error message simply says, that the element you want to click on is present, but it is not visible. It could be covered by something or temporary not visible.

There could be many reasons why the element is not visible in the moment of the test. Please re-analyse your page and find proper solution for your case.

Solution for particular case:

In my case, this error occures, when a tooltip of the screen element i just clicked on, was poping over the element I wanted to click next. Defocus was a solution I needed.

  • Quick solution how to defocus would be to click to some other element in another part of the screen which does "nothing" resp. nothing happens after a click action.
  • Proper solution would be to call element.blur() on the element poping the tooltip, which would make the tooltip disapear.
Dee
  • 282
  • 1
  • 9
2

I was facing the same problem with clj-webdriver (clojure port of Selenium). I just translated the previous solution to clojure for convenience. You can call this function before doing click or whatever to avoid that problem.

(defn scrollTo
  "Scrolls to the position of the given css selector if found"
  [q]
  (if (exists? q) 
    (let [ loc (location-once-visible q) jscript (str "window.scrollTo(" (:x loc) "," (:y loc) ")") ] 
      (execute-script jscript))))
Jaime Agudo
  • 8,076
  • 4
  • 30
  • 35
2

Maybe it's not really clean solution but it works:

try:
    el.click()
except WebDriverException as e:
    if 'Element is not clickable at point' in e.msg:
        self.browser.execute_script(
            '$("{sel}").click()'.format(sel=el_selector)
        )
    else:
        raise
radeklos
  • 2,168
  • 21
  • 19
2

I was getting this bug because I tested a hover and then needed to click on the link underneath the tooltip. The solution was to add page.find('.sp-logo').hover before click_link to get the tooltip out of the way.

Dan Kohn
  • 33,811
  • 9
  • 84
  • 100
2

It's funny, all the time I spent looking at the various responses, no one had tried the obvious, which of course, I hadn't either. If your page has the same id used multiple times, as mine did, ("newButton",) and the one you want is not the first one found, then you will in all likelihood get this error. The easiest thing to do (C#):

var testIt = driver.FindElements(By.Id("newButton"));

Note it's FindElements, not FindElement.

And then test to see how many results came back from the retrieval. If it's the second one, you can then use:

testit[1].Click();

Or get whomever reused ids to fix them.

CargoMeister
  • 4,199
  • 6
  • 27
  • 44
  • If this is because there are multiple buttons by that ID and only one is displayed at a time, a superior solution involves using LINQ to find the first element that is visible (append `.First(x => x.Visible)` to the FindElements call) and click on that if it's not null. – Sean Duggan Nov 05 '15 at 18:48
2

After testing all mentioned suggestions, nothing worked. I made this code. It works, but is not beautiful

public void click(WebElement element) {
    //https://code.google.com/p/selenium/issues/detail?id=2766 (fix)
    while(true){
        try{
            element.click();
            break;
        }catch (Throwable e){
            try {
                Thread.sleep(200);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
    }
}

public void click(String css) {
    //https://code.google.com/p/selenium/issues/detail?id=2766 (fix)
    while(true){
        try{
            driver.findElement(By.cssSelector(css)).click();
            break;
        }catch (Throwable e){
            try {
                Thread.sleep(200);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
    }
}
JoeyC
  • 764
  • 11
  • 19
Bruno Lee
  • 1,867
  • 16
  • 17
2

If you have jQuery loaded on the page, you can execute the following javascript command:

"$('#" + element_id + "').click()"

Example using python executor:

driver.execute_script("$('#%s').click()" % element_id)
Zags
  • 37,389
  • 14
  • 105
  • 140
2

I do a kind of brute force of clicks and it works for me.

try:
    elem.click()
except:
    print "failed to click"
    size = elem.size
    mid_of_y = int(size["height"])/2
    stepts_to_do_to_left = int(size["width"])
    while stepts_to_do_to_left > 0:
        try:
            print stepts_to_do_to_left, mid_of_y
            action = webdriver.common.action_chains.ActionChains(driver)
            action.move_to_element_with_offset(elem, mid_of_y, stepts_to_do_to_left)
            action.click()
            action.perform()
            print "DONE CLICK"
            break
        except:
            pass
Super Mario
  • 923
  • 10
  • 16
2

Try to maximize the browser when you are working with resolutions greater than 1024x768.

driver.manage().window().maximize();
D.JCode
  • 386
  • 2
  • 12
2

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 :)

Sanyam Gupta
  • 258
  • 3
  • 8
1

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>
Jordan Silva
  • 833
  • 8
  • 18
  • Not surprised that caused you issues. There should only be one id on a page. That was unwinding bad design not a workaround. – Dave Lawrence Aug 09 '16 at 11:12
1

I had the same issue and got the 'other element would receive the click' error for a displayed, visible element. I found no other solution that to trigger the click with a javascript.

I replaced:

WebElement el = webDriver.findElement(By.id("undo-alert"));
WebElement closeButton = el.findElement(By.className("close"));
// The following throws 'Element is not clickable at point ... Other element 
// would receive the click'
closeButton.click();

with:

((JavascriptExecutor) webDriver).executeScript(
    "$('#undo-alert').find('.close').click();"
);

and it all worked out fine

mwikblom
  • 351
  • 2
  • 4
1

I had the same problem and spent hours in finding the solution. I tried to click a cell at the bottom of a long ngGrid using protractor. Here is a snapshot of my ngGrid html:

....many rows here..
<!- row in renderedRows ->
   <!- column in renderedColumns ->
   <div ...> <a ngclick="selectRow(row)"...>the test link 100000</a>...
....

all clicking function did not work. The solution is to use evaluate in the element's current scope:

element(by.cssContainingText("a", "the test link 100000"))
    .evaluate("selectRow(row)")
chfw
  • 4,502
  • 2
  • 29
  • 32
1

I had another bug where find_link on Chrome and Poltergeist could not click an A tag with an EM tag and some text inside of it, although it worked fine in Firefox and rack_test. The solution was to replace click_link(link) with:

find('a em', text: link).click
Dan Kohn
  • 33,811
  • 9
  • 84
  • 100
1

In Visual Studio 2013, if you enable BrowserLink - it displays a BrowserLink navbar at the bottom of the screen. If the item you want to click is behind that navbar, it give the error. Disabling BrowserLink solved the problem for me.

Jim Sowers
  • 368
  • 3
  • 7
1

I had same exception while trying to click one of the radio buttons on my page. I used below Javascript and exeted using IJavaScriptExecutor. C# example

string script=" function clickCharity() {"+
"var InputElements = document.getElementsByName('Charity');"+
  "for (i=0; i<InputElements.length; i++){"+
    "if(InputElements[i].getAttribute('value') == 'true')"+
    "{"+
        "InputElements[i].click();"+
    "}"+
"}"+
"}";
var js=WebDriver as IJavaScriptExecutor;
js.ExecuteScript(script);
JSDeveloper
  • 178
  • 8
1

Instead of

webdriver.findElement(By.id("id1")).click();

try to use

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

You may simulate click with JS:

public void click(WebElement element) {
    JavascriptExecutor js =(JavascriptExecutor)driver;
    js.executeScript("document.elementFromPoint(" + element.getLocation().x + "," + element.getLocation().y + ").click();");
}
Andrey
  • 853
  • 9
  • 27
1

If you are having this issue with a modal (pop-up), note that it may be that another element with the same properties exists underneath the current top level modal. This caught me out, just increase the specificity of your selector to reduce the scope to that of the modal you are trying to click only.

Tom Dickman
  • 169
  • 2
  • 5
1

I was having this exact issue when clicking a button within an Angular Material menu. Whenever I clicked a button inside a menu, the .cdk-overlay-pane would receive the click. The solution is to increase the z-index of buttons inside the menu.

.cdk-overlay-pane button {
  z-index: 1001;
}

umutesen
  • 2,523
  • 1
  • 27
  • 41
1

There may be lots of factor which will throw this error. Firstly, the dom may be changed after selenium webdriver captured the element or all the java scripts used in elements is not loaded successfully before capturing the element. To fix this we need to use javascript wait or ajax wait like as follow.

wait = new WebDriverWait(driver, 30);
wait.until((ExpectedCondition<Boolean>) wd -> ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
        e_driver = new EventFiringWebDriver(driver);

Secondly, most of the engineers of companies providing software qa services try using java script executor for the click action.

If this also doesn't work then perform action using Actions class.

Vishal
  • 121
  • 1
0

I ran into this problem and it seems to be caused (in my case) by clicking an element that pops a div in front of the clicked element. I got around this by wrapping my click in a big 'ol try catch block.

Code Silverback
  • 3,204
  • 5
  • 32
  • 39
0

In Drupal when using 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();
Alex Skrypnyk
  • 1,331
  • 13
  • 12
0

I am facing the same issue and I used delay and it is working fine my side. Page was getting refresh and getting the other locators.

Thread.sleep(2000);
        Click(By.xpath("//*[@id='instructions_container']/a"));
Adnan Ghaffar
  • 1,345
  • 7
  • 26
  • 46
0

If you're using the line below in your conf.js file, please comment it out and try again

browser.ignoreSynchronization = true;
JoeyC
  • 764
  • 11
  • 19
nrs
  • 937
  • 3
  • 17
  • 42
0

In my case, it worked in Firefox but failed in Chrome. In Chrome, it got fixed after updating Chrome driver version to the latest.

Balram Singh
  • 1,576
  • 19
  • 30
  • This question is 5+ years old and I still got the issue today, it was an overlay for me that I needed to remove – Dorian Feb 20 '18 at 20:52
0

In Rselenium, this happened with code successfully used many times when a link was positioned at the top window border. Simple solution was to use sendKeysToElement() as follows.

if (unlist(webElem$isElementDisplayed())) {
    webElem$sendKeysToElement(list(key = "up_arrow"))  # Add "up arrow"..
    webElem$clickElement()  # ... before $clickElement
LWRMS
  • 547
  • 8
  • 18
0
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.<Id or anything>));

Hope this helps.

Ayush Goel
  • 54
  • 7
0

This might help someone who is using WebdriverIO:

function(){
    var runInBrowser = function(argument) { 
        argument.click();
    };
    var elementToClickOn = browser.$('element');
    browser.execute(runInBrowser, elementToClickOn);
}

Source : https://www.intricatecloud.io/2018/11/webdriverio-tips-element-wrapped-in-div-is-not-clickable/

web-auto-bot
  • 63
  • 2
  • 11
0

This can also happen if you are trying to click on a input or button that is disabled, in that case there nothing overlapping the element, but it's not clickable.

lucaswxp
  • 2,031
  • 5
  • 23
  • 34
0

Debugging "Element is not clickable at point" error

To handle this error scroll down using this code.

browser.execute_script("window.scrollTo(0, 300);")