skip to Main Content

I’ve got this project in mind. Part of it is logging in a facebook account.
This code works perfectly on my local machine(windows) and local server(ubuntu) but it doesn’t work when i run it on an online linux server.

def login_facebook(driver, email, password):
    try:
        logging.info("Logging into Facebook...")
        driver.get('https://www.facebook.com')

        email_input = WebDriverWait(driver, 30).until(
            EC.presence_of_element_located((By.ID, 'email'))
        )
        logging.info("Email found")
        email_input.send_keys(email)

        password_input = WebDriverWait(driver, 30).until(
            EC.presence_of_element_located((By.ID, 'pass'))
        )
        logging.info("Password found")
        password_input.send_keys(password)
        password_input.send_keys(Keys.RETURN)
        logging.info("Keys sent")

        # Adjust XPath or use a different locator strategy
        WebDriverWait(driver, 120).until(
                EC.visibility_of_element_located((By.XPATH, '//*[@aria-label="Facebook"]'))
            )
        logging.info("Logged into Facebook successfully.")
    except Exception as e:
        error_message = f"Error while logging into Facebook: {str(e)}"
        logging.error(error_message)
        send_error_email(error_message)

After hours of debbuging i still couldn’t figure out how to solve it, but I know what doesn’t work.
The code works perfectly until it’s checking for ‘//*[@aria-label="Facebook"]’.
All the time passes and the login fails.
As i said before, the code works perfectly on my windows machine and on my local ubuntu server with no changes at all so it’s quite hard to find a solution.

I’ve tried to change the aria-label to something else but still nothing.

Here’s the error even if it’s not very straight forward, maybe it can help:

2024-07-21 03:01:02,836 - ERROR - Error while logging into Facebook: Message:
Stacktrace:
#0 0x639c45d33c4a <unknown>
#1 0x639c45a2e29c <unknown>
#2 0x639c45a79bc1 <unknown>
#3 0x639c45a79cb1 <unknown>
#4 0x639c45abdf94 <unknown>
#5 0x639c45a9c96d <unknown>
#6 0x639c45abb33a <unknown>
#7 0x639c45a9c6e3 <unknown>
#8 0x639c45a6c879 <unknown>
#9 0x639c45a6d1ce <unknown>
#10 0x639c45cfc96f <unknown>
#11 0x639c45d00af6 <unknown>
#12 0x639c45ce979c <unknown>
#13 0x639c45d01291 <unknown>
#14 0x639c45ccf6ce <unknown>
#15 0x639c45d230d8 <unknown>
#16 0x639c45d232e6 <unknown>
#17 0x639c45d32cfd <unknown>
#18 0x7cdf49edeac3 <unknown>

Any help is greatly appreciated.

2

Answers


  1. Chosen as BEST ANSWER

    I found a solution using driver.save_screenshot(). I was able to see what was happening on the screen by sending the picture to my machine. I had to change the way the code checked if I'm connected to WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[contains(@aria-label, "Accueil") or contains(@aria-label, "Home")]'))).


  2. You can also use Selenium Grid, which is able to see what is happening on a Linux server.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search