Foobar
Foobar

Reputation: 8477

Selenium - Logging Into Facebook Causes Web Driver to Stall Indefinitely

I have a simple program that logs into Facebook and gets 3 urls:

def setup_driver():
    prefs = {"profile.default_content_setting_values.notifications": 2}
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_experimental_option("prefs", prefs)
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--no-sandbox')
    driver = webdriver.Chrome(executable_path="./chromedriver_linux",
                              chrome_options=chrome_options)
    return driver

def log_into_facebook(driver):
    driver.get("https://www.facebook.com/")
    email_field = driver.find_element_by_id("email")
    email_field.send_keys("<MY EMAIL ADDRESS>")
    password_field = driver.find_element_by_id("pass")
    password_field.send_keys("<MY FB PASSWORD>")
    driver.find_element_by_id("loginbutton").click()

if __name__ == "__main__":

    driver = setup_driver()
    log_into_facebook(driver)
    print("before getting url 1")
    driver.get('https://facebook.com/2172111592857876')
    print("before getting url 2")


 #Stackoverflow is breaking indentation
driver.get('https://www.facebook.com/beaverconfessions/posts/2265225733546461')
    print("before getting url 3")
    driver.get('https://www.facebook.com/beaverconfessions/posts/640487179353666')
    print("finished getting 3 urls")

On my local machine, this program runs fine. However, on my AWS EC2 instance, this program makes my instance unusable (the Python script will hang/stall after "before getting url 2" is printed to the console. While the script is hanging, the EC2 instance will become so slow that other programs on the instance will also stop working properly. I need to forcefully close the program with Ctrl-C in order for the instance to start being responsive again.). However, if I comment out log_into_facebook(driver), then the program runs fine.

I would try to get an stacktrace, but the program doesn't actually crash, rather it just never reaches "before getting url 3".

It is worth nothing, previously I was getting "invalid session id" errors with a program that was similar to this (it also logged into Facebook and then called driver.get several times).

Update: Removing the --no-sandbox option from the webdriver seemed to fix the problem. I'm not sure why. I originally had this option in place because I was previously having a "unable to fix open pages" error, and I read that "--no-sandbox" would fix the error.

Upvotes: 2

Views: 56

Answers (1)

J_H
J_H

Reputation: 20470

    chrome_options.add_argument('--no-sandbox')

Roymunson reports that the appropriate way to fix the hanging problem is:

Avoid specifying the --no-sandbox option in the webdriver.

Upvotes: 1

Related Questions