function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Smita LokhandeSmita Lokhande 

SFDC asking for 2 step verification for every login using Selenium

Hi All,
I am working on application, where after login application ask for VerificationCode which will send to registered email and after passing that verficationcode to application it is not allowing me to go to Home screen.

Note : When I am Manully Login it only asking me for first time only. but while selenium automation it is asking me for evry login step.

Kindly suggest how I can avoid this step of verifcation? is there any way to pass security Token or maybe remember/add cookies in selenium.
NagendraNagendra (Salesforce Developers) 
Hi Smita,

You will need to get Selenium to retrieve the cookies and save them.
Set<Cookie> allCookies = driver.manage().getCookies();
I would recommend persisting these to a file - then retrieving them again
so the logic would be:
  • open your cookie file
  • If you find it - add it to your driver (driver.manage().addCookie(cookie);)
  • If you don't find it - then get it from the driver and save it to the cookie file
There is a good article on this here: Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra
Lisa Lu 9Lisa Lu 9
I'm running into a similar problem. I'm using the cookies approach, but since we are trying to write a fully automated script, it won't work since the cookies expire. Is there any other way to bypass the 2FA?