Fix 2FA (language setting is not always working)

This commit is contained in:
augustin64 2024-04-10 11:04:54 +02:00
parent ba66a96c65
commit 49dc53ed32
2 changed files with 27 additions and 14 deletions

37
V6.py
View File

@ -10,6 +10,7 @@ from modules.driver_tools import *
from modules.error import *
import os
from selenium.common.exceptions import NoSuchElementException
# create a webdriver
def create_driver(mobile=False):
@ -383,22 +384,30 @@ def login_part_1():
driver = config.WebDriver.driver
driver.get("https://login.live.com")
wait_until_visible(By.ID, "i0116", browser=driver)
mail_elem = driver.find_element(By.ID, "i0116")
send_keys_wait(mail_elem, config.UserCredentials.get_mail())
mail_elem.send_keys(Keys.ENTER)
send_wait_and_confirm(
driver.find_element(By.ID, "i0116"),
config.UserCredentials.get_mail()
)
wait_until_visible(By.ID, "i0118", browser=driver)
pwd_elem = driver.find_element(By.ID, "i0118")
send_keys_wait(pwd_elem, config.UserCredentials.get_password())
pwd_elem.send_keys(Keys.ENTER)
custom_sleep(2)
send_wait_and_confirm(
driver.find_element(By.ID, "i0118"),
config.UserCredentials.get_password()
)
# 2FA
if "Entrez le code de sécurité" in driver.page_source:
try:
a2f_elem = driver.find_element(By.ID, "idTxtBx_SAOTCC_OTC")
a2f_elem.send_keys(config.UserCredentials.get_tfa().now())
a2f_elem.send_keys(Keys.ENTER)
except Exception as err:
log_error(err)
try:
wait_until_visible(By.ID, "idTxtBx_SAOTCC_OTC", browser=driver, timeout=5)
a2f_code = config.UserCredentials.get_tfa().now()
info(f"Need 2FA, I have code: {a2f_code}")
send_wait_and_confirm(
driver.find_element(By.ID, "idTxtBx_SAOTCC_OTC"),
a2f_code
)
except NoSuchElementException:
custom_sleep(2)
pass
except Exception as err:
log_error(err)
# Accept all cookies question, and check if the account is locked

View File

@ -60,6 +60,10 @@ def send_keys_wait(element, keys: str) -> None:
element.send_keys(i)
sleep(uniform(0.1, 0.3))
def send_wait_and_confirm(element, keys: str) -> None:
send_keys_wait(element, keys)
element.send_keys(Keys.ENTER)
# Wait for the presence of the element identifier or [timeout]s
def wait_until_visible(search_by: str, identifier: str, timeout: int = 20, browser=None) -> bool: