{"action":"created","issue":{"url":"https://api.github.com/repos/Corion/WWW-Mechanize-Chrome/issues/15","repository_url":"https://api.github.com/repos/Corion/WWW-Mechanize-Chrome","labels_url":"https://api.github.com/repos/Corion/WWW-Mechanize-Chrome/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/Corion/WWW-Mechanize-Chrome/issues/15/comments","events_url":"https://api.github.com/repos/Corion/WWW-Mechanize-Chrome/issues/15/events","html_url":"https://github.com/Corion/WWW-Mechanize-Chrome/issues/15","id":339014064,"node_id":"MDU6SXNzdWUzMzkwMTQwNjQ=","number":15,"title":"Add infinite scroll function?","user":{"login":"sdondley","id":2506364,"node_id":"MDQ6VXNlcjI1MDYzNjQ=","avatar_url":"https://avatars1.githubusercontent.com/u/2506364?v=4","gravatar_id":"","url":"https://api.github.com/users/sdondley","html_url":"https://github.com/sdondley","followers_url":"https://api.github.com/users/sdondley/followers","following_url":"https://api.github.com/users/sdondley/following{/other_user}","gists_url":"https://api.github.com/users/sdondley/gists{/gist_id}","starred_url":"https://api.github.com/users/sdondley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sdondley/subscriptions","organizations_url":"https://api.github.com/users/sdondley/orgs","repos_url":"https://api.github.com/users/sdondley/repos","events_url":"https://api.github.com/users/sdondley/events{/privacy}","received_events_url":"https://api.github.com/users/sdondley/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2018-07-06T17:19:53Z","updated_at":"2018-07-06T20:21:20Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I have created a wrapper for WMC (with Moose) that includes a method for scrolling down to the bottom of a page with an infinite scroll and then waits for more elements to load. I'm wondering if it might be useful to improve it and incorporate into the WMC module. One call to the function will cause the browser to scroll down to the bottom of the page (twice just to make sure it registers) and then return once it detects more elements have been loaded. Here it is along with its helper functions:\r\n\r\n```\r\nsub infinite_scroll {\r\n  my $s = shift;\r\n  my $wait_time = shift || 120;\r\n\r\n  my $current_element_count = $s->get_element_count;\r\n  $s->scroll_to_bottom;\r\n\r\n  # wait 1/10th sec for more of the page to load\r\n  usleep 100000;\r\n\r\n  my $new_element_count = $s->get_element_count;\r\n\r\n  my $start_time = time();\r\n  while (($new_element_count - $current_element_count) < 10) {\r\n\r\n    # wait for wait time\r\n    if (time() - $start_time > $wait_time) {\r\n      return 0;\r\n    }\r\n\r\n    # wait 1/10th sec for more of the page to load\r\n    usleep 100000;\r\n    $new_element_count = $s->get_element_count;\r\n  }\r\n  usleep 100000;\r\n  return 1;\r\n}\r\n\r\nsub scroll_to_bottom {\r\n  my $s = shift;\r\n  $s->eval( 'window.scroll(0,document.body.scrollHeight + 100)' );\r\n  usleep 100000;\r\n  $s->eval( 'window.scroll(0,document.body.scrollHeight + 200)' );\r\n}\r\n\r\nsub get_element_count {\r\n  my $s = shift;\r\n  my ($el_count) = $s->eval( 'document.getElementsByTagName(\"*\").length' );\r\n  return $el_count;\r\n}\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Corion/WWW-Mechanize-Chrome/issues/comments/403137124","html_url":"https://github.com/Corion/WWW-Mechanize-Chrome/issues/15#issuecomment-403137124","issue_url":"https://api.github.com/repos/Corion/WWW-Mechanize-Chrome/issues/15","id":403137124,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMzEzNzEyNA==","user":{"login":"Corion","id":142199,"node_id":"MDQ6VXNlcjE0MjE5OQ==","avatar_url":"https://avatars1.githubusercontent.com/u/142199?v=4","gravatar_id":"","url":"https://api.github.com/users/Corion","html_url":"https://github.com/Corion","followers_url":"https://api.github.com/users/Corion/followers","following_url":"https://api.github.com/users/Corion/following{/other_user}","gists_url":"https://api.github.com/users/Corion/gists{/gist_id}","starred_url":"https://api.github.com/users/Corion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Corion/subscriptions","organizations_url":"https://api.github.com/users/Corion/orgs","repos_url":"https://api.github.com/users/Corion/repos","events_url":"https://api.github.com/users/Corion/events{/privacy}","received_events_url":"https://api.github.com/users/Corion/received_events","type":"User","site_admin":false},"created_at":"2018-07-06T20:21:20Z","updated_at":"2018-07-06T20:21:20Z","author_association":"OWNER","body":"I usually run the single tests as\r\n\r\n    perl -Ilib -w t/99-that-test.t\r\n\r\nThat way, I don't need to bother with `make` etc."}}
{"actor":{"display_login":"Corion"}}