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:
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
UPDATE For additional information, use this class to open the browser and simulate with Firefox (obviously this is just a part of the code. I don't insert it all to keep the question concise)
class Facebook:
#Access Facebook
#/usr/bin/firefox/firefox
profile_path = '....'
options=Options()
options.set_preference('profile', profile_path)
options.set_preference('network.proxy.type', 4)
options.set_preference('network.proxy.socks', '127.0.0.1')
options.set_preference('network.proxy.socks_port', 9050)
options.set_preference("network.proxy.socks_remote_dns", False)
#options.set_preference("network.cookie.cookieBehavior", 0) #http://kb.mozillazine.org/Network.cookie.cookieBehavior
service = Service('/home/xxxx/bin/geckodriver')
global driver
driver = Firefox(service=service, options=options)
driver.set_window_size(600, 990)
driver.set_window_position(1, 1)
driver.get("http://www.facebook.com")
#Cookie prima del login
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button[data-cookiebanner="accept_button"]'))).click()
#Login
username_box = driver.find_element(By.ID, 'email')
username_box.send_keys(email.get())
password_box = driver.find_element(By.ID, 'pass')
password_box.send_keys(password.get())
#Open link
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div[2]/div[1]/div/div/div/div[2]/div/div[1]/form/div[2]/button'))).click()
#Click on icon-blu like
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@class='j1lvzwm4']"))).click()
#Click on All
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[1]/div/div[4]/div/div/div[1]/div/div[2]/div/div/div/div[1]/div/div/div/div/div[2]/div[2]'))).click()
CodePudding user response:
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:
driver.maximize_window()
driver.implicitly_wait(30)
wait = WebDriverWait(driver, 20)
driver.get("https://www.facebook.com/")
#try:
#Cookie prima del login
#WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button[data-cookiebanner="accept_button"]'))).click()
#except:
#pass
#Login
wait.until(EC.visibility_of_element_located((By.ID, "email"))).send_keys('user id here')
wait.until(EC.visibility_of_element_located((By.ID, "pass"))).send_keys('password here')
#Click on login
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[name='login']"))).click()
time.sleep(2)
driver.get("https://www.facebook.com/nytimestravel/photos/a.142272672496512/5176942835696112/")
time.sleep(2)
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[@aria-label='See who reacted to this']"))).click() #this is to click on like, and reaction button
time.sleep(4)
# Click on All
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[1]/div/div[4]/div/div/div[1]/div/div[2]/div/div/div/div[1]/div/div/div/div/div[2]/div[2]'))).click()
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}]")))
time.sleep(0.5)
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