I have following code to scroll down a javascript enabled website. Problem is when the newHeight reaches around 229275 I get list out of range on the line browser.find_elements_by_class_name('alt')[0].click(). But why I am getting this error and how can I solve this?
My code:
browser = webdriver.PhantomJS("phantomjs")
browser.get(url)
while True:
time.sleep(pause)
newHeight = browser.execute_script("return document.body.scrollHeight")
print newHeight
browser.find_elements_by_class_name('alt')[0].click()
find_elements_by_class_nameis called. It's either no longer present or not yet present. Try to wait for it or handle the case where it's no longer present.