Kevin
Kevin

Reputation: 95

One Click vs Two Clicks

Scenario:

Issue: Sometimes elements needs one click and the test passes but if I run it again the same element needs double clicks

This is causing my test to fails randomly

I verified this by changing the command to have a double click in protractor and it passed.

This is causing inconsistency as I don't know when the element needs one or double clicks.

Any Suggestion is appreciated?

Upvotes: 1

Views: 202

Answers (3)

Sudharsan Selvaraj
Sudharsan Selvaraj

Reputation: 4832

you can use browser.executeScripts to inject native javascript code into the browser and click the required button. this will execute the click event on the required element that you pass into the function

try the below code,

var elementToBeClick=element(locator);
browser.executeScript("arguments[0].click()",elementToBeClick.getWebElement())

Upvotes: 0

Optimworks
Optimworks

Reputation: 2547

Inconsistency might be because of element is not yet ready to click. So you need to wait until element become clickable and click it. Below code will help you in achieving consistency.

 Code Snippet:

  var EC = protractor.ExpectedConditions;
  var elementToBeClick=element(locator);
  var timeOut=10000;

  browser.wait(EC.elementToBeClickable(elementToBeClick), timeOut).
      thenCatch(function () {
                assert.fail(' target element is not clickable');
             });
  elementToBeClick.click();

Upvotes: 0

alecxe
alecxe

Reputation: 473823

You may just need to put the element into focus explicitly via mouseMove() and then issue a click() action:

browser.actions().mouseMove(elm).click().perform();

Upvotes: 0

Related Questions