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
4
  • what you want to achieve ..?? why are you scrolling down..?? Commented Apr 19, 2021 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. Commented Apr 19, 2021 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 stackoverflow.com/questions/32391303/… Commented Apr 19, 2021 at 22:11
  • driver.set_window_size(1920, 1080) and then run the same code again, then it works. Thank you :D Commented Apr 20, 2021 at 1:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.