简体   繁体   中英

Python - Selenium : Scroll down not working because of PopUp

I am writing a python script using selenium to login to Facebook and then do some scrapping. For that purpose, I have to scroll down to the bottom of the page. I think the pop that you can see in the picture is the cause of this. Here is the snippet of code which does the following thing

elem = driver.find_element_by_id("email")
elem.send_keys(usr)
elem = driver.find_element_by_id("pass")
elem.send_keys(pwd)
elem.send_keys(Keys.RETURN)

driver.get("https://www.facebook.com/jatin.wadhwa.52/friends?source_ref=pb_friends_tl")
time.sleep(10)

element_new = driver.find_element_by_tag_name('html')
element_new.send_keys(Keys.ESCAPE)
element_new.send_keys(Keys.END)

#driver.execute_script("window.scrollTo(0, 1000);")
f = driver.find_elements_by_xpath("//ul")

在浏览器中弹出图片

Solved.

Adding this will resolve and woulndt allow any such pop ups.

    chrome_options = webdriver.ChromeOptions()
    prefs = {"profile.default_content_setting_values.notifications" : 2}
    chrome_options.add_experimental_option("prefs",prefs)
    #driver = webdriver.Chrome(chrome_options=chrome_options)

driver = webdriver.Chrome(r"C:\Users\jatin\Downloads\chromedriver_win32\chromedriver.exe",chrome_options=chrome_options)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM