Element is not clickable at point using chrome driver

When you are trying to click on a element using chrome driver you may come across the error element is not clickable at this point.

This is due to the chrome driver always clicks the middle of the element in attempt to be faithful to what an actual user does.

The chrome driver first identifies the location of the element then clicks the middle of the element.

So if you are trying to click on a moving element, the chrome driver tries to clicks at the position where it first finds that element. And at the time of clicking , if the element is not at the same position, then chrome driver throws the error "Element is not clickable at this position". 

You may get this error in the following cases.

1. If the position of the element is changing in the DOM. 
2. If you are applying transformations/transitions/animations to that element.
3. If you are trying to click on a element before it gets loaded etc.

You don't face any problem when you are testing in IE or FF. You mostly face this issue when you are testing on chrome.

Quick Fix for Element is not clickable at point:


After reading all the discussions in the webdriver community at this page  https://code.google.com/p/selenium/issues/detail?id=2766 , i have found some quick fixes with which you can solve this issue

1. Many people are facing this issue only after upgrading to newer version of Chrome Driver
In the older version we have implicit waits, which waits for the element to be fully loaded. But now we have to explicitly wait for the element to load. 

We can do this by telling the browser to sleep for some time (say 2 seconds).

We have the following commands to tell the browser to sleep for some 'x' seconds  (choose the command based on your testing tool)

browser.sleep(2000); // for angular e2e testing using protractor
Thread.Sleep(2000); // for selenium webdriver

2. I see one more work around in the comment 27 in the above page

Scroll the element into view before clicking it.

For Javascript with webdriver:

IWebElement element = driver.findElement(By.xpath('element xpath'));
(driver as IJavaScriptExecutor).ExecuteScript(string.Format("window.scrollTo(0,{0});",element.Location.Y));
element.Click();

You cal also try following code

WebElement element = driver.findElement(By.xpath('element xpath'));
((JavaScriptExecutor) driver).ExecuteScript("window.scrollTo(0,"+element.getLocation().y+")");
element.click();

For Python:

ActionChains(w).move_to_element_with_offset(link,0,20).click().perform();

For Ruby with Capybara and selenium web-driver

#where @session is Capybara::session instance
#and object is a Capybara::Node::Element istance
@session.driver.execute_script "window.scrollTo(#{object.native.location.x},#{object.native.location.y})"
return_string = object.native.click 

Using the above work arounds you can solve the issue "Element is not clickable at point"

2 comments:

  1. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. Selenium Training

    ReplyDelete
  2. Hi... I am working on Cucumber framework. Can you please share the code snippet for same issue in Javascript language.

    Thanks in advance!!

    ReplyDelete