I'm setting a session with chrome in which is a need to log in the website with username, password and an OTP (one-time-Password) which is sent on the phone. The OTP is for browser only, which means if I enter a username, password and OTP in chrome once, next time it will ask me for username and password only not for OTP. I'm using selenium-python to automate this and selenium always open a new browser Window. How can I overcome this situation?
I tried to save the cookies and then get it to load on the driver but still asking for OTP.
# Saved functions are below.
import pickle
# Path = "E:\\Python\\cookies\\cookies.pkl".
def save_cookie(driver, path):
"""
Save cookies in cookies folder.
"""
with open(path, 'wb') as filehandler:
pickle.dump(driver.get_cookies(), filehandler)
def load_cookie(driver,path):
"""
Load cookies from the saved folder.
"""
with open(path, 'rb') as cookiesfile:
cookies = pickle.load(cookiesfile)
for cookie in cookies:
driver.add_cookie(cookie)
# Here is what I'm trying.
from selenium import webdriver
from udf import cookies
import pickle
driver = webdriver.Chrome()
driver.get('https://somewebsite.com/')
cookies.save_cookie(driver,'E:\\Python\\cookies\\cookies.pkl')
cookies.load_cookie(driver, 'E:\\Python\\cookies\\cookies.pkl')
driver.refresh()
I still need to submit OTP for the Chrome browser.