1
votes

I would like to scroll down, up to the maximum end of the scroll (up to the last person's name), the list of people who have left a like on Facebook (in the "All" section). The link, for example from a New York Time post, is this: https://www.facebook.com/nytimestravel/photos/a.142272672496512/5176942835696112/ (maybe to view you have to log in with your facebook, I don't know)

I am using this code, but it is not working:

#code for access to facebook with driver in firefox
#(i avoid writing so as not to stretch and be more synthetic)
# ....

#scrollbar
element = driver.find_element(By.XPATH,'/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div/div[2]/div/div[1]/div/div[3]')
driver.execute_script("return arguments[0].scrollIntoView();", element)

enter image description here

I'm not getting any errors, but the problem is, using this code, nothing happens. The vertical scrollbar does not move and the list does not scroll down

I've tried using several xpatches, but they don't work. I am using this code. I don't know if I'm wrong to enter the xpatch or if the whole code is wrong. Can anyone help me? Thanks

1

1 Answers

0
votes

Once the propmt for reaction opens (in div), you can use the below xPath

//div[@data-visualcompletion='ignore-dynamic' and not(@role) and not(@class)]

This will target each and every row in that prompt.

Code:

wait = WebDriverWait(driver, 30)
i = 1
while True:
    try:
        row = wait.until(EC.visibility_of_element_located((By.XPATH, f"(// div[@ data-visualcompletion='ignore-dynamic' and not ( @ role) and not (@class )])[{i}]")))
        driver.execute_script("arguments[0].scrollIntoView(true);", row)
        i = i + 1
    except:
        print('Scrolled all the element, and must have not found the index hence break from the loop')
        break

You'd have to import:

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