1

I am trying to get to the bottom of a webpage so that all the items are on the page before I run a script to find a specific item. However, I have to scroll down at least 5 or so times to allow more items to load. Is there a way to get all items to load right away so that I do no need to scroll?

questionier
  • 359
  • 1
  • 5
  • 15
  • 3
    exactly how depends on how the items are being added, but you will need to modify the in-place scripting to get it to play nice with such a process. if the site uses an ajax call to fetch more items, perhaps you can just spoof that and side-step the human activity simulation. – dandavis Jul 05 '16 at 20:20
  • 2
    Please show your code. Else it's difficult to help. What you need is to show what you tried and what you're having difficulty with. – SoluableNonagon Jul 05 '16 at 20:25
  • Possible duplicate of [Scroll Automatically to the Bottom of the Page](http://stackoverflow.com/questions/11715646/scroll-automatically-to-the-bottom-of-the-page) Did you search for this at all? I found numerous stack questions regarding this. Why not use the onReady event for the document? all elements should be ready by that point. As @SoluableNonagon said, without code it will be difficult to help you. – Richard Barker Jul 05 '16 at 20:27

3 Answers3

1

To answer your question, you can add this to your script and call it in a loop to keep scrolling until you find your item:

window.scrollTo(0, document.body.scrollHeight); See here Scroll Automatically to the Bottom of the Page

You can also trying look at the Network tab in Chrome console (or other dev consoles) to see if there is some API you can try to access.

Community
  • 1
  • 1
Keith Holliday
  • 1,692
  • 21
  • 15
1

You can use the DOMSubtreeModified event like so:

html:

<div id='container'></div>

javascript:

document.getElementById('container').addEventListener('DOMSubtreeModified', function () {
  window.scrollTo(0, document.body.scrollHeight);
}, false);

Assuming your items are dynamically added to the div with id=container.

Note: this is not going to win a beauty contest.

Sander Sluis
  • 160
  • 7
0

If your using pure JavaScript, use async attribute.

<script async>
//This will load the script after HTML body has been loaded.
</script>

For jQuery, you can use either async or $(document).ready(function() { });

This way you can let your document body be loaded first.

Chaitanya
  • 719
  • 9
  • 23