question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

browser.actions().click() does not work with async/await

See original GitHub issue

Hi, I am converting my protractor tests from Promises to async/await and I found something weird with browser actions click. The problem is that the click() does not execute, but the mouseMove does. The click() works when test is written as a promise not async/await

Here is the test and the browser.actions function

  it('When entering selection state selection toolbar should appear', async () => {
    const page = new SingleObjectPage();
    await page.get('barchart', 'PWFwr', 'select=clearall');
    await page.activateSelectionMode($(barlayer));
    await browser.wait(EC.visibilityOf($(SingleObjectPage.selectors.object.confirmButton)), timeout, 'Confirm button did not appear');
  });

  activateSelectionMode(element) {
    return browser.actions()
      .mouseMove(element, {
        x: 20,
        y: 75,
      })
      .click()
      .perform();
  }

I found a workaround to get it to work.

  activateSelectionMode(element) {
    return browser.actions()
      .mouseMove(element, {
        x: 20,
        y: 75,
      })
      .perform().then(() => browser.actions()
        .click()
        .perform());
  }

Bug report

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:14
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
BrianMaldocommented, Jul 11, 2018

Note: I am using a wrapper class for element. Replace this.webElement with your element variable.

This is how I am doing it with async and await:

await browser.actions()
             .mouseMove(this.webElement.getWebElement(), {x: 10, y: 10,})
             .perform();

return  await browser.actions().doubleClick().perform();
3reactions
Jacob-McKaycommented, Jan 23, 2019

I’m doing this in an ‘actions wrapper’:

await browser.actions().mouseMove(elementToClick).perform();
await browser.actions().click(elementToClick).perform();

Which is lame sauce because the docs for ActionSequence.click() say:

If an element is provided, the mouse will first be moved to the center of that element. This is equivalent to:

     sequence.mouseMove(element).click()

Trying to move away from control flow as that seems like the recommended approach, this is an obstacle to that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Protractor browser.actions().dragandDrop async await not ...
I have found this solution to work. I am going to implement it into a helper function moving forward. await browser.actions().
Read more >
Use Promise.all to Stop Async/Await from Blocking Execution ...
To see these in action, open up developer tools ( command + option + I ), copy paste the code sample into the...
Read more >
for await...of - JavaScript - MDN Web Docs
The for await...of statement creates a loop iterating over async iterable objects as well as sync iterables. This statement can only be used ......
Read more >
How JavaScript works: Event loop and the rise of Async ...
This means that the browser can't render, it can't run any other code, it's just stuck. And here comes the problem — your...
Read more >
angular/protractor - Gitter
Only problem I have found is that browser.pause etc. stops working if you do. ... mouseMove(element(by.id(passwordID))).click().perform(); }).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found