Noob Master 69
Noob Master 69

Reputation: 109

How can I scroll down using selenium

The code is as below.

driver = webdriver.Chrome(chromedriver_path) #webdriver path

driver.get('https://webtoon.kakao.com/content/%EB%B0%94%EB%8B%88%EC%99%80-%EC%98%A4%EB%B9%A0%EB%93%A4/1781') #website access
time.sleep(2)

driver.execute_script("window.scrollTo(0, 900)") #scroll down
time.sleep(1)

However, the page does not scroll.

How can I scroll?

Page link to be scrolled

Upvotes: 4

Views: 9306

Answers (3)

httpanand
httpanand

Reputation: 225

Try this

driver.execute_script("window.scrollTo(100,document.body.scrollHeight);")

Upvotes: 5

cruisepandey
cruisepandey

Reputation: 29372

The webapp is dynamic (which is, the more you scroll down, more you will see the data), you can perform infinite scrolling like below :-

driver = webdriver.Chrome(chromedriver_path) #webdriver path
driver.maximize_window()
driver.implicitly_wait(30)
driver.get('https://webtoon.kakao.com/content/%EB%B0%94%EB%8B%88%EC%99%80-%EC%98%A4%EB%B9%A0%EB%93%A4/1781') #website access
time.sleep(2)
wait = WebDriverWait(driver, 20)
time.sleep(5)
action = ActionChains(driver)
i = 3
while True :
  action.move_to_element(driver.find_element(By.XPATH, f"(//div[contains(@class, 'AspectRatioBox_aspectRatioBox')])[{i}]")).perform()
  i = i +1
  time.sleep(.5)

Imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

Upvotes: 1

pmadhu
pmadhu

Reputation: 3433

Tried with the below code, it did scroll.

driver.get("https://webtoon.kakao.com/content/%EB%B0%94%EB%8B%88%EC%99%80-%EC%98%A4%EB%B9%A0%EB%93%A4/1781")
time.sleep(2)
options = driver.find_element_by_xpath("//div[@id='root']/main/div/div/div/div[1]/div[3]/div/div/div[1]/div/div[2]/div/div[1]/div/div/div/div")
driver.execute_script("arguments[0].scrollIntoView(true);",options)

Upvotes: 3

Related Questions