while True:
    elemsCount = browser.execute_script(
        "return document.querySelectorAll('.stream-items > li.stream-item').length"
        )
browser.execute_script('window.scrollTo(0, document.body.scrollHeight);')
try:
    WebDriverWait(browser, 20).until(lambda x: x.find_element_by_xpath(
        "//*[contains(@class,'stream-items')]/li[contains(@class,'stream-item')]["
         + str(elemsCount + 1) + ']'))
except:
    break
Scroll down to bottom of infinite page with PhantomJS in Python