How to “scroll down” some part using selenium in python?
Because the scroll is actually inside an element, all the javascript command with window. will not work. Also the element is not interactable so Key down is not suitable too.
I suggest using scrollTo javascript executor and set up a variable which will increase through your loop:
element = driver.find_element_by_xpath('//div[@id="container1"]')
time.sleep(10)
verical_ordinate = 100
for i in range(0, 50):
print(verical_ordinate)
driver.execute_script("arguments[0].scrollTop = arguments[1]", element, verical_ordinate)
verical_ordinate += 100
time.sleep(1)
I have tested with chrome so it should work.
Reference
https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTop
How can I scroll down using selenium
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)
How to scroll down in Python Selenium step by step
Agree with answer of @Rahul Chawla.
But adding one change. You can try this one
driver = webdriver.Chrome()
read_mores = driver.find_elements_by_xpath('//a[text()="Read More..."]')
for read_more in read_mores:
driver.execute_script("arguments[0].scrollIntoView();", read_more)
driver.execute_script("$(arguments[0]).click();", read_more)
Is there a way to scroll up a particular div element in a webpage using selenium with PYTHON?
Yes, there are multiple ways using which you could scroll to particular element
By using the move_to_element()
element = driver.find_element_by_xpath("_element_")
action = ActionChains(driver)
action.move_to_element(element).perform()
By scrollIntoView()
element = driver.find_element_by_xpath("_element_")
driver.execute_script("arguments[0].scrollIntoView(true);", element)
For reference check here
Related Topics
Most Efficient Way to Forward-Fill Nan Values in Numpy Array
Calculate Final Letter Grade in Python Given 4 Test Scores
Sklearn Error Valueerror: Input Contains Nan, Infinity or a Value Too Large for Dtype('Float64')
Get the Last Sunday and Saturday'S Date in Python
Finding the Two Closest Numbers in a List Using Sorting
How to Set the Default Python Path for Anaconda on Linux
Python Opencv - Add Alpha Channel to Rgb Image
Pandas Concat: Valueerror: Shape of Passed Values Is Blah, Indices Imply Blah2
Test If Dictionary Key Exists, Is Not None and Isn't Blank
How to Pass a Dictionary Object as Parameter for a Function in Python
Python - Converting a List of 2 Digit String Numbers to a List of 2 Digit Integers
Beautifulsoup: Get the Contents of a Specific Table
Package Only Binary Compiled .So Files of a Python Library Compiled With Cython
How to Use Ffmpeg in a Python Function
How to Check Whether All Elements of Array Are in Between Two Values