javascript - Is there a way to trigger scroll event with HtmlUnit or is it not possible at all? -


I am currently learning HtmlUnit to scour the websites.

I have tried several ways, which I want to face with a dynamic page (for example, I am using Pinterest's website). Trigger scrolling in a real browser (I'll show them below). Before proceeding, I would like to mention that I have the following configuration already defined:

  webclient.setJavaScriptEnabled (true); Webclient.setAjaxController (new opt-in syncExpress controller ());  

Let's say I want to get all my followers on Pinterest. I navigate to that page and now for the first time when you are only 24, I want to scroll down, the event that turns Ajax call on the server and retrieves the next set of followers.

1) Simplified javascript or jQuery code to scroll through windows.

  ScriptResult sr = Followers page ExecuteJavaScript ("window.scrollBy (0,1000)"); // jquery // scriptResult sr = A version in the follower Page. ExecuteJavaScript ("$ (window) .scrollTop (0,1000);"); // Also tried with body, html / animation, // scriptResult sr = Followers page Execute javascript ("$" ("html, body"). Chetan ({scrollTop: $ (document) .height ()}, 1000); "); Webclient.waitForBackgroundJavaScript (10000); Followers page = (HtmlPage) sr.getNewPage ();  

=> When I check the top distance, it equals 0 and the result is similar to the original page. When debugging in eclipse, when I step on the line where Javascript is executed, it goes straight to the next line without any delay if I write any other JavaScript, for example:

  ScriptResult sr = Followers Page. ExecuteJavaScript ("$ (div.GridItems) .html ('new content')");  

You can see that the debugger hangs half a second on that line, which means that Javascript is executed.

2) Change the focus to a follower anchor other (I chose anchor because this focus is used in order when you click on the tab key):

  HTMLDivision gridItems = Followers page .getFirstByXPath ("// div [contains (concat (', @ square,'), 'grid id')]"); & Lt; HtmlDivision & gt; ELS = (list & gt; HTML division & gt;) gridItems.getByXPath ("// div [@ class = 'item']"); & Lt; HtmlDivision & gt; Item = (list & gt; HTML division & gt;) gridItems.getByXPath ("// div [@ class = 'item']"); (HTML Division Items: Items) {HTMLEnchor A = Iitact.fbbxpath ("//A [@class = 'UserWeeker']"); Center (); WebClient.waitForBackgroundJavaScript (1000); } Followers page = (HtmlPage) webClient.getCurrentWindow (). GetEnclosedPage ();  

Again, no scrolls occurred. The results page remains the same in the original form

3) Create a button that triggers scroll events on windows:

  HtmlButton scrollButton = (HtmlButton) followers. Page .createElement ("button"); ScrollButton.setAttribute ("Type", "Button"); ScrollButton.setAttribute ("onclick", "window.scrollTo (0, document.body.scrollHeight);"); GridItems.appendChild (scrollButton); Followers page = scroll button. Click (); 

Unfortunately, this does not work.

I tried many other ways but there is no positive result till now.

I have many related articles, here also on the StackarVarflflow, concerning that topic. And it seems that no one managed to scroll using HtmlUnit because most questions remain unanswered. This is the reason why I am thinking that this facility was ever functional.

Does anyone manage to scroll a page (ordinary page, no Ajax)? Does anyone manage to scroll a page, the event that calls some AJAX calls?


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -