0

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
Rina K
  • 1
  • 1
  • what you want to achieve ..?? why are you scrolling down..?? – Hietsh Kumar Apr 19 '21 at 21:32
  • probably different screen resolutions. You can set a specific size for the browser window, (driver.manage().window()...right after you launch the driver) which will probably make the results much more similar. – pcalkins Apr 19 '21 at 21:41
  • Its because of your screen resolution and the content in your website is loading dynamically. You have to scroll your page to see the element and then get data. Please use https://stackoverflow.com/questions/32391303/how-to-scroll-to-the-end-of-the-page-using-selenium-in-python – Swaroop Humane Apr 19 '21 at 22:11
  • driver.set_window_size(1920, 1080) and then run the same code again, then it works. Thank you :D – Rina K Apr 20 '21 at 01:16

0 Answers0