The code is supposed to scroll to the bottom of the webpage, but it seems to go at first then oldHeight and newHeight do not change values properly.
I have tried to return the window innerheight and the Yoffset methods but neither worked as well as just "return document.body.scrollHeight" they all either return the same value no matter what position im at on the screen or don't change the value when im at a different section of the screen. I have also tried the window.scrollTo that just doesnt work all together by not scrolling down the screen. What i've settled on scrolls once but the value of the screen only changes once and i've tried sending down the screen with page down multiple times before changing the value, but that also doesnt work. here's the code
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("https://www.google.com/search?client=firefox-b-1-d&q=NFL+game+dates#sie=lg;"
"/g/11k4hhjvj6;6;/m/059yj;mt;fp;1;;;2023-08-04T00:00:00Z/robots.txt")
driver.maximize_window()
body = driver.find_element(By.CSS_SELECTOR, "body")
oldHeight = driver.execute_script("return document.body.scrollHeight")
while True:
print(oldHeight)
body.send_keys(Keys.PAGE_DOWN)
time.sleep(2)
newHeight = driver.execute_script("return document.body.scrollHeight")
print(newHeight)
if newHeight == oldHeight:
break
else:
oldHeight = newHeight
driver.close()
I'm sorry if this is a really noob question
Edit: Added an answer that works for me