I'm using two computer, a desktop/a notebook, and running my same code but getting different result.
The versions of the chrome browser and chromedriver are perfectly the same.
What brings the situation?
My code :
from selenium import webdriver
import time
driver = webdriver.Chrome('c:\chromedriver.exe')
driver.get(url) # it's dynamic loading page
new_height = 0
current_height = -1
while new_height != current_height:
current_height = driver.execute_script("return document.body.scrollHeight")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(3)
new_height = driver.execute_script("return document.body.scrollHeight")
print(">> scrollTo:", current_height, new_height)
Result in PC1 (desktop, chrome version:90.0.4430.72(64bit), python 3.8.8)
C:\JetBrains\Projects\scrollTest\venv\Scripts\python.exe C:/JetBrains/Projects/scrollTest/main.py
>> scrollTo: 4521 6382
>> scrollTo: 6382 8308
>> scrollTo: 8308 10233
>> scrollTo: 10233 12111
>> scrollTo: 12111 14005
>> scrollTo: 14005 15914
>> scrollTo: 15914 17777
>> scrollTo: 17777 17963
>> scrollTo: 17963 17963
Process finished with exit code 0
Result in PC2 (notebook, chrome version:90.0.4430.72(64bit), python 3.8.8)
C:\JetBrains\PycharmProjects\scrollTest\venv\Scripts\python.exe C:/JetBrains/PycharmProjects/scrollTest/main.py
>> scrollTo: 2659 18134
>> scrollTo: 18134 18134
Process finished with exit code 0