Selenium page scrolling no longer works
Question:
I have the following problem: my page scrolling in Selenium stopped working, I was scrolling pages with the same code just yesterday, the next day I sat down at my computer and scrolling no longer works.
I do not understand what the problem, I guess I have to remove all the python, a browser and ChromeDriver reinstall, maybe then solve the problem, but before that I would like to know from you, maybe there is another solution?
The code, which exactly worked, is shown below, even if you can even just leave one single line:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
that scrolls, and there will still be no scrolling):
# Load the data until we reach the end date
while (True):
search_results = driver.find_elements(By.CLASS_NAME, "EventItem__item-2z3yK")
last_date = get_date_from_string(search_results[-1:][0].text)
if check_date_interval(last_date):
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
else:
break
To find out what the problem is:
- I created a separate project with nothing but scrolling;
- I tried different sites and different methods, (about 3) up to scrolling with "Send.Keys";
- I cleared the project of all libraries, and install them again, later versions;
But none of it worked.
I expect the scrolling to finally start working, I don’t understand why it worked two days before and stopped on the third.
Answers:
Best and easiest way is to scroll to a specific element of the page, in this case the last search result
driver.execute_script('arguments[0].scrollIntoView({block: "center", behavior: "auto"});', search_results[-1])
I have the following problem: my page scrolling in Selenium stopped working, I was scrolling pages with the same code just yesterday, the next day I sat down at my computer and scrolling no longer works.
I do not understand what the problem, I guess I have to remove all the python, a browser and ChromeDriver reinstall, maybe then solve the problem, but before that I would like to know from you, maybe there is another solution?
The code, which exactly worked, is shown below, even if you can even just leave one single line:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
that scrolls, and there will still be no scrolling):
# Load the data until we reach the end date
while (True):
search_results = driver.find_elements(By.CLASS_NAME, "EventItem__item-2z3yK")
last_date = get_date_from_string(search_results[-1:][0].text)
if check_date_interval(last_date):
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
else:
break
To find out what the problem is:
- I created a separate project with nothing but scrolling;
- I tried different sites and different methods, (about 3) up to scrolling with "Send.Keys";
- I cleared the project of all libraries, and install them again, later versions;
But none of it worked.
I expect the scrolling to finally start working, I don’t understand why it worked two days before and stopped on the third.
Best and easiest way is to scroll to a specific element of the page, in this case the last search result
driver.execute_script('arguments[0].scrollIntoView({block: "center", behavior: "auto"});', search_results[-1])