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.
Any help is greatly appreciated.