I have an button on my page that is visible when the user scrolls down. Because of this, protractor tests give me an error:
UnknownError: unknown error: Element is not clickable at point (94, 188).
I tried using:
browser.executeScript('window.scrollTo(0,document.body.scrollHeight)');
which worked when I tested it in protractors elementexplorer.js but in my regular tests it doesn't do anything. Any other way around this?
I'd like to add to the previous answer, and hopefully provide a little more explanation.
This code, in the call to 'executeScript':
If you know you want to be at the very bottom of the window, which was my goal. You can put a very large number in the 'y' coordinate, like I did here:
I found that creating a util helper and using it inside page objects (or the test files themselves) helped. This seems to work well for me:
utils.js
inside page object somewhere...
in the test itself...
In case anyone else is having troubles like I was:
I was trying to scroll to the bottom of the page to load my next set of data in an infinite scroll scenario. I tried different variations of window.scrollTo as well as arguments[0].click() with no success.
Finally I realized, to get the page to scroll, I had to bring focus to the "window" by clicking on any element within the window. Then window.scrollTo(0, document.body.scrollHeight) worked liked a charm!
example code:
The answer of this question was marked correct at top replied.But after upgrade the newest chrome v54.The following code maybe best solution.
you need to wait for the promise to be solved. the following example comes from an open issue
Update: This is an old question (May of 2014), but it still gets some visitors. To clarify:
window.scrollTo(0, 0)
scrolls to the top left corner of the current page.If you want to scroll to the buttom of your page you could call
window.scrollTo(0, document.body.scrollHeight)
as mentioned by @jsuser in this answer
A more modern approach would be using
browser.actions().mouseMove(element).perform();
Upvotes to @MartinBlaustein in this answer
Other way, you can try this: