How to automate social logins when enters into otp page
Answer a question
I am trying to automate social logins (FB, Gmail, OneDrive, LinkedIn). I have written script using Selenium in Python as below
driver = webdriver.Chrome()
driver.get('<social_url_site>')
driver.find_element_by_id('username').send_keys('user_name')
driver.find_element_by_id('password').send_keys('password')
driver.find_element_by_id('submit_button').click()
It is working fine in my system (Chrome).When I am trying to launch same scripts in another system (remote), after login, it is redirecting to otp page so all test cases related logins gets failed Any suggestion to overcome from this issue?
Answers
Dont try otp automation in selenium this is not good practice in selenium Two Factor Authentication shortly know as 2FA is a authorization mechanism where One Time Password(OTP) is generated using “Authenticator” mobile apps such as “Google Authenticator”, “Microsoft Authenticator” etc., or by SMS, e-mail to authenticate. Automating this seamlessly and consistently is a big challenge in Selenium. There are some ways to automate this process. But that will be another layer on top of our Selenium tests and not secured as well. So, you can avoid automating 2FA.
There are few options to get around 2FA checks:
- Disable 2FA for certain Users in the test environment, so that you can use those user credentials in the automation.
- Disable 2FA in your test environment.
- Disable 2FA if you log in from certain IPs. That way we can configure our test machine IPs to avoid this
更多推荐

所有评论(0)