'Object Not interactable while trying to scroll down a pop up using Selenium on Python

I need to scroll down a pop up that appears in the following link https://www.vivino.com/IT/en/ronchi-di-cialla-picolit-di-cialla/w/2015576?year=2011&price_id=23500586 (or any other wine link on vivino) after clicking on 'show more reviews', but when i try to scroll i get the Element not Interactable error. The code to open the reviews pop up is the following

from urllib.request import urlretrieve
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import pandas as pd
import csv
import re
import time
import random



target_url = 'https://www.vivino.com/IT/it/ronchi-di-cialla-picolit-di-cialla/w/2015576?year=2011&price_id=23500586'
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("useAutomationExtension", False)




driver = webdriver.Chrome(options=options)
driver.get(target_url) #apre la pagina

last_height = driver.execute_script("return document.body.scrollHeight") 

while True:
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight/3);")
    time.sleep(1)
    driver.execute_script("window.scrollTo(document.body.scrollHeight/3, document.body.scrollHeight*2/3);")
    time.sleep(1)
    driver.execute_script("window.scrollTo(document.body.scrollHeight*2/3, document.body.scrollHeight);")
    
    new_height = driver.execute_script("return document.body.scrollHeight")
    if new_height == last_height:
        break
    last_height = new_height
    
driver.find_element(By.CSS_SELECTOR, "button[class='MuiButtonBase-root MuiButton-root jss1 MuiButton-outlined jss3 MuiButton-disableElevation']").click()


Solution 1:[1]

Here is the code scrolling down to each review every 1 second. I suggest you to not loop directly on reviews, i.e. don't do something like

reviews = driver.find_elements(By.XPATH, "//div[contains(@class, 'allReviews__reviews')]/child::div")
for review in reviews:
    ...

because initially only few reviews are loaded, and then as you scroll down more are loaded. So if you use the code above reviews will only contain the first loaded reviews. The code below solves this problem, but it will fail if the number of total reviews is smaller than limit. So you should improve the code to take into account also this fact

target_url = 'https://www.vivino.com/IT/it/ronchi-di-cialla-picolit-di-cialla/w/2015576?year=2011&price_id=23500586'
driver.get(target_url)
# go to reviews section
driver.get(target_url + '#all_reviews')
# click on show more reviews
driver.find_element(By.XPATH, "//span[contains(text(), 'Mostra altre recensioni')]/../..").click()
# scroll down to each review, one by one in a loop
limit = 20
for idx in range(limit):
    reviews = driver.find_elements(By.XPATH, "//div[contains(@class, 'allReviews__reviews')]/child::div")
    driver.execute_script('arguments[0].scrollIntoView({block: "center", behavior: "smooth"});', reviews[idx])
    time.sleep(1)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sound wave