20

I use the following docker image to run my cucumber tests:

https://hub.docker.com/r/selenium/standalone-chrome/

Unfortunately, starting from today it seems that whenever I run my tests I get the errors below. They appear at the start of each test. It does not matter what I do on the page.

**13:38:26 [exec] org.openqa.selenium.ElementNotInteractableException: element not interactable: element has zero size

13:38:26 [exec] (Session info: chrome=83.0.4103.61)**

I did some digging and I noticed the chromedriver version was updated from 81 to 83. I managed to fix this issue by using an older docker image from that docker hub link which has chromedriver 81. But if I attempt to use chromedriver 83 again it will not work.

Has anyone else encountered this? Is there a new chrome option I need to add because of the update?

Robert Curetean
  • 333
  • 1
  • 3
  • 9

10 Answers10

22

The root cause of that issue is that Chrome doesn't scroll to the element outside of the viewport. Instead of it, Chrome tries to click on it outside of the viewing area. That's why the issue appears. It is definitely an issue with Chrome 83 because I didn't face it on Chrome 81.

Moreover, I have no such issue on Windows machine, it reproduced only on Linux (I'm using selenoid docker images).

Solution with a click via JS is not the best option, because via JS you can click anywhere even for unclickable elements (e.g. overlapped by other objects). It's an unsafe operation.

Instead of this, I would suggest scrolling to the element before click and after native click(); it will work just perfectly.

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].scrollIntoView(true);", element);    
element.click();
danronmoon
  • 3,814
  • 5
  • 34
  • 56
kalumpiwarra
  • 246
  • 1
  • 8
  • 5
    this answer is great, but instead of scrolling using javascript, you can use selenium "move_to_element" option like this: from selenium.webdriver.common.action_chains import ActionChains ActionChains(driver).move_to_element(element).perform() element.click() – Avishay116 Jun 15 '20 at 12:04
  • I am getting this in windows 10 with chrome 85 – PHPGuru Sep 23 '20 at 21:03
7

I'm getting this error also, i did some digging, i found that the element size contains 0, for example an element of size 200 x 0 will get you this error if you want to click on it. This is not a docker only error, i'm getting it on local chrome 83.

Try clicking on element using the Javascript Executor:

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);
Wael.B
  • 71
  • 3
  • This seems to work, but I need to add this in almost each cucumber step. I'll come back to this solution if everything else fails. – Robert Curetean May 27 '20 at 19:13
  • 1
    this solution works for me, thanks! fwiw, i'm on chrome 83, ruby, rspec, running headless on our CI server. Replaced element.click with calls to this method: def click_link(element) execute_script("arguments[0].click();", element) end – TimCO May 28 '20 at 15:22
6

I got around this by using the --window-size argument when I'm using headless chrome. E.g. chrome --headless --window-size=400,800.

I do not know what changed or why this is a sufficient workaround.

John
  • 69
  • 1
  • 1
    Unfortunately, I already have the --window-size argument and it still does not work. I cannot switch to headless because it will cause all my download tests to stop working. – Robert Curetean May 27 '20 at 19:11
4

In our case, the root cause was a CSS/HTML problem: an anchor was wrapping a div and expected to implicitly gain a size from that of this child element.

Previous versions of Chrome had been tolerant of this, but from v.83 Chrome seems to have become stricter on this front.

So, in this case the solution was to change from something like this:

<a href="http://example.org">
  <div class="class with style giving height and width">
    some content
  </div>
</a>

To something like this:

<a href="http://example.org" class="class with style giving height and width">
  some content
</a>

This is valid HTML5.

Rob Lucas
  • 81
  • 3
  • Thanks, this is a better approach IMO than having to do hacky JS on the test side. Investigating the DOM first led me to solve the problem more elegantly than throwing in JS executor. – k_rollo Oct 21 '21 at 07:19
3

I ended up using scrollIntoView() which did the trick (below code is from Protractor test):

// scroll to it
browser.executeScript('document.getElementById("targetID").scrollIntoView()');

browser.sleep(500);

// click it
element(by.id('targetID')).click();
yaryar123
  • 185
  • 1
  • 8
1

I got around it by clicking a child <input> element inside the element that supposedly had zero width.