I’m working on a Instagram autosub project. It’s a dynamic website, so I would need to scroll down. I know how to do this in the MAIN window, but since Interest are a pop-up window this solution to scroll doesn’t work.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
chrome_option = webdriver.ChromeOptions()
chrome_option.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=chrome_option)
driver.get(url="https://www.instagram.com/accounts/login")
USER = "USER"
EMAIL = ("EMAIL")
PASSWORD = "PASSWORD"
try:
cookies = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[contains(text(), 'Allow all cookies')]"))
)
cookies.click()
enter_email = driver.find_element(By.XPATH, value='//input[@name="username"]')
enter_email.send_keys(EMAIL)
enter_password = driver.find_element(By.XPATH, value='//input[@name="password"]')
enter_password.send_keys(PASSWORD)
enter_password.send_keys(Keys.ENTER)
not_now = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "div ._ac8f div"))
)
not_now.click()
not_now2 = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//button[contains(text(), "Not Now")]'))
)
not_now2.click()
driver.get(url=f"https://www.instagram.com/{USER}/")
follows = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//a[contains(@href, '/following')]"))
)
follows.click()
fBody = driver.find_element(By.XPATH, "//html/body/div[6]/div[2]/div/div/div[1]/div/div[2]/div/div/div/div/div[2]/div/div/div[4]']")
scroll = 0
while scroll < 5:
driver.execute_script('arguments[0].scrollTop = arguments[0].scrollTop + arguments[0].offsetHeight;', fBody)
time.sleep(2)
scroll += 1
except Exception as e:
print(e)
I’ve looked at stachoverflow, asked the GPT chat, looked at a bunch of videos, but nothing’s helped.
Selenium Python: How to Scroll Down in a Pop Up window
Why scroll on modal/popup doesn’t working on instagram
Even these didn’t help.
Could it be just a problem with this version of Instagram?
Y B is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.