1

I have an app which includes a button that you click which scrolls the page using JS.

I get a "Element is not clickable at point (somepoint,somepoint)" error, I think this is because selenium/protractor isn't aware of the dynamic scroll and so isn't waiting for it, how can I set a specific time to wait before attempting the next action?

Melbourne2991
  • 11,707
  • 12
  • 44
  • 82

2 Answers2

0

You can use protractor expected conditions like

var EC = protractor.ExpectedConditions;

buttonThatScrolls.click();
var nextElement = $('#xyz'));
browser.wait(EC.presenceOf(nextElement), 10000);
nextElement.click();
nilesh
  • 14,131
  • 7
  • 65
  • 79
  • I ended up just using browser.wait(), however your solution might be better, is EC.presenceOf equivalent to `browser.wait(function () { return (elmLocator).isPresent(); }, 3000);`? because I tried that and it didn't work – Melbourne2991 Jan 15 '16 at 01:38
  • @Melbourne2991 Like all WebdriverJS methods `isPresent()` returns a promise and wait expects a function to return true/false. So your method should be like `browser.wait(function () { return (elmLocator).isPresent().then( return function(isPresent) { return isPresent;}); }, 3000);` – nilesh Jan 16 '16 at 03:57
  • Also `EC.presenceOf` uses `isPresent`. Check protractor code [here](https://github.com/angular/protractor/blob/master/lib/expectedConditions.js#L288-L290) – nilesh Jan 16 '16 at 03:59
0

You may also need to move to element before clicking:

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

Or scroll into it's view:

browser.executeScript("arguments[0].scrollIntoView();", elm);

Note that there is a hacky workaround - click the element via javascript:

browser.executeScript("arguments[0].click();", elm);

which may work as is, but make sure you know the difference:


And, to add to the @nilesh's answer, elementToBeClickable expected condition sounds like a better fit in this particular case:

browser.wait(EC.elementToBeClickable(elm), 5000);
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195