Sarah Guegan
Sarah Guegan

Reputation: 23

Python Selenium Page Scroll Down (the page is divided in two, 2 scollers)

I'm looking to scroll down the conversation part on facebook messenger .

the page contains 2 scrollers, i'm looking to scroll down the scroller number 1 check the picture

Here is the link to the page (you should be logged in and have more than 25 messages) : https://www.facebook.com/messages/t/ enter image description here

my actual code :

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys

opt = Options()
opt.add_argument("--disable-infobars")
opt.add_argument("start-maximized")
driver = webdriver.Chrome('chromedriver path', options=opt)

# go to fb
driver.get("https://www.facebook.com/")
time.sleep(5)

# login to fb
email = driver.find_elements_by_xpath("//input[@name='email']")
email.sendkeys("youremail")
pass = driver.find_elements_by_xpath("//input[@name='pass']")
pass.sendkeys("yourpassword")
time.sleep(3)

# go to facebook messenger
driver.get("https://www.facebook.com/messages/t/")

# this is what i've tried but didn't work
# start scroling
html = driver.find_element_by_tag_name('html')
html.send_keys(Keys.END)

Upvotes: 0

Views: 2141

Answers (1)

Amruta
Amruta

Reputation: 1166

We have many options to scroll down however i checked fb manually.Page down ,end ,down arrow keys doesn't work on scroll bar 1.

Option 1 javascript executor may help in this case and using name of your buddy in your messenger.

element=driver.find_element_by_xpath('//span[contains(text(),'nameofyourbuddy')]//ancestor-or-self::div[position()=3]')

driver.execute_script("arguments[0].scrollIntoView();", element)

or scroll to bottom page using element

element=driver.find_element_by_xpath("//*[@aria-label='Conversation List']/child::*[last()]")
driver.execute_script("arguments[0].scrollIntoView();", element)

Option 2 to scroll bottom of the page if you don't have any specific element to scroll down

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

Upvotes: 1

Related Questions