How to log in to a 2FA site, mobile BankID, using Selenium and Python?

Is is possible to use Selenium to log in to a site that uses a 2 factor autentication method (e.g bankID for a bank)?

driver = webdriver.Firefox(executable_path=r"C:Program Files (x86)geckodriver.exe")
# driver.implicitly_wait(2)


    personNumber = WebDriverWait(driver, 5).until(
        EC.presence_of_element_located((By.NAME, "personNumber")))


except TimeoutException:
    print("Failed to load BankID-page")

The above code makes you manually log in to the site using e.g. your phone as the second factor where you input the password.

But if I go to a new site, and the site is requesting a new log in with BankID when I go to a new page on the site, is it possible to store the log in session the first time? So it is persistent even when I go to a new page on the site.


Please check their official documentation:

It advises you to either disable it or if you can log in using another method that should work.

Leave a Reply

Your email address will not be published. Required fields are marked *