Search code examples
pythonseleniumwebdriverbrowserstack

Infinite Scroll Up-Down with Python Selenium in Browserstack


This my test code for selenium but i need infinite scroll up and down. I did some research but I got this error all the time;

STOP SESSION BROWSERSTACK_IDLE_TIMEOUT

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

desired_cap = {
 'browser': 'Firefox',
 'browser_version': '77.0',
 'os': 'Windows',
 'os_version': '10',
 'resolution': '1024x768',
 'name': 'Bstack-[Python] Sample Test'
}

driver = webdriver.Remote(
    command_executor='https://something',
    desired_capabilities=desired_cap)

driver.get("http://something")

I think any infinite scoll up&down code can fix this error.


Solution

  • Browserstack defaults the timeout to 90 seconds in case you do not explicitly state the timeout duration.

    A capability to set the timeout is:

    'browserstack.idleTimeout': 300
    

    The value can go up to maximum 300 seconds. You can check the capability page here: https://www.browserstack.com/automate/capabilities

    I found a good article that you can read upon to achieve infinite scrolling:

    https://dev.to/hellomrspaceman/python-selenium-infinite-scrolling-3o12

    It works by scrolling the entire page height and waiting for a short duration before scrolling further.