0

Sometimes I get this error but not every time I run the test. What is causing this strange behavior?

Failed: element click intercepted: Element <div id="myButton">...</div> is not clickable at point (616, 104). Other element would receive the click: <div class="wrapper">...</div> (Session info: headless chrome=77.0.3865.120) (Driver info: chromedriver=77.0.3865.120 (416d6d8013e9adb6dd33b0c12e7614ff403d1a94-refs/branch-heads/3865@{#884}),platform=Linux 4.15.0-70-generic x86_64)

file.html

<div class="wrapper">
  <div id="myButton">Add</div>
</div>

file.e2e-spec.ts

it('Example test', async () => {
  await element(by.id('myButton')).click();
  ...
});

Francesco
  • 405
  • 3
  • 15

2 Answers2

1

Finally I wrote a custum function that wait until the element is prensent and clickable before perform the click on it.

util.ts

export const click = async (el: ElementFinder, time: number = 4000) => {
    await browser.wait(EC.presenceOf(el), time);
    await browser.wait(EC.elementToBeClickable(el), time);
    return el.click();
};

file.e2e-spec.ts

import * as pt_util from '../../util';
...

it('Example test', async () => {
  await pt_util.click(element(by.id('myButton')));
  ...
});
Francesco
  • 405
  • 3
  • 15
0

try adding an explicit wait?

const EC = protractor.ExpectedConditions;
const button = element(by.id('myButton'));

await browser.wait(EC.elementToBeClickable(button), 5000);
await button.click();
Joaquin Casco
  • 704
  • 5
  • 14
  • Thanks for the answer. Should I do this check every time I need to click some element? – Francesco Feb 04 '20 at 11:57
  • 1
    @Francesco well it depends on the element. With protractor you usually don't need to. But to prevent flakiness, I use a function where it waits for the element to be clickable, then clicks it (an element you pass as a parameter), and use that function everytime instead of doing the above for each element I want to click – Joaquin Casco Feb 04 '20 at 12:15