Issue
I am trying to scroll to the end of a page so that I can make all the data visible and extract it. I tried to find a command for it but it's available in java (driver.executeScript) but couldn't find for python. Right now I am making the computer press the end key thousand times:
while i<1000:
scroll = driver.find_element_by_tag_name('body').send_keys(Keys.END)
i+=1
And I also tried driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
but it scrolls to the end of the loaded page and the same thing END key does. Once at the bottom of the page, next content loads. But now it doesn't scroll again.
I know there will be a very nice alternative for this.
How do I scroll to the end of the page using selenium in Python?
Solution
Well I finally figured out a solution:
lenOfPage = driver.execute_script("window.scrollTo(0, document.body.scrollHeight);var lenOfPage=document.body.scrollHeight;return lenOfPage;")
match=False
while(match==False):
lastCount = lenOfPage
time.sleep(3)
lenOfPage = driver.execute_script("window.scrollTo(0, document.body.scrollHeight);var lenOfPage=document.body.scrollHeight;return lenOfPage;")
if lastCount==lenOfPage:
match=True
Answered By - Prabhjot Singh Rai
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.