Reputation: 155
When I click on my follower's page on instagram, a dialog box appears and I need it to scroll down and through the list. My current code works but the issue is that it scrolls too quickly and because of that instagram locks it out from viewing more profiles. What command can I use to lower scroll speed to more closely mimic a human?
WebDriverWait(driver, 10).until(lambda d: d.find_element_by_css_selector('div[role="dialog"]'))
driver.execute_script('''
var fDialog = document.querySelector('div[role="dialog"] .isgrP');
fDialog.scrollTop = fDialog.scrollHeight
''')
Upvotes: 0
Views: 520
Reputation: 19967
You can write a function that scrolls a certain amount of pixels, then pause for a certain amount of milliseconds until a target scroll length is reached.
function scrollByPixels(px, pause, target) {
document.documentElement.scrollTop += px
if (target > px) {
setTimeout(scrollByPixels, pause, px, pause, target - px)
}
}
scrollByPixels(10, 100, 1000)
body {
height: 1000px;
background-image: linear-gradient(to bottom, dodgerblue, indigo);
}
Usage:
scrollByPixels(10, 100, 1000)
References:
Upvotes: 1