First time trying the forum, but today having trouble running selenium scripts with Salesforce. Everytime Im running a script locally I get a two step verification screen. I then have to input the code I receive, and then progress with my tests. Although the problem is, Everytime I run selenium scripts same accounts, even though I have done the verification and it then repeats the same process. When going to sign in This had only started recently as of yesterday as we had tests running on jenkins everyday.

Just wondering If anyone ever encountered this, or is it a problem with my set up.

Thanks very much

  • just a guess: does selenium delete all it's cookies ? Jan 28 '16 at 9:50
  • I also faced same issue after January 27 release, right now this occurs in sandbox environment. Anyone can easily reproduce by logging in at chrome incognito-->Enter code-->Close browser and re login (It will again ask for code). Please suggest any way to disable this feature.
    – user28277
    Jan 29 '16 at 13:15

We had this problem as well starting on 1/27 and we decided to add the IP address that Selenium uses for running our automated tests. You can find that IP address by going to (via Setup- Manage Users) the login/username profile in Salesforce that you use for running your Selenium Automated tests then look at the Login History section for that user.

  • Ye I ended up just doing this and worked then straight away for me and my tests :) Feb 12 '16 at 17:01
  • 1
    Fun fact, you can also just google "my ip"
    – Adrian Larson
    Feb 18 '16 at 18:16

Please follow the Step:

  1. Login in your Org.
  2. Click on Setup then Administration Setup then Security Controls then Network Access now click on New .
  3. Set the IP address of your network or full IP range and save. (Eg. Start IP Address : and End IP Address: )
  4. Now use your script you should not get the verification screen.
  • you get Error: Invalid Data. if you have such broad range of ip
    – Nick Kahn
    Mar 17 '18 at 16:09

I am having the very same problem with our Salesforce test automation and just using a browser profile that has the Salesforce cookies does not work for me - or more precisely - it works only the first time. It seems that even when using a custom Firefox profile Selenium runs the tests in a copy of that profile. Any changes in the cookies that happen during the test execution are not persisted for the next time you run the tests.

On the other hand it seems that Salesforce changes something with each login and expects to find the changed status the next time, in order to skip the second factor authentication. I am curious - did you have this problem?

I am using the Java Selenium bindings with Firefox. Maybe other browsers and language bindings do not have this problem - I was able to find an option to persist the changes in the browser profile in the C# language bindings, but not for java.

Here is a link to the related ticket in the Selenium issue tracker: https://code.google.com/p/selenium/issues/detail?id=1954


Yes it is related to cookies, please create a custom profile and login to Salesforce, now use profile in your selenium code. It worked good for me.


Go to Setup->Manage Users->Your user Profile->Check your profile type(for example. mine was System Administrator)->Click on it->go to 'Login IP ranges'->Give IP Start Address as and IP End Address as and Save it. No authentication code would be generated for login in any browser/any system if your hitting IP address resides between ( to

No need to modify your automation code.

  • This essentially disables 2FA, which is a big security concern.
    – Ryan Guest
    Feb 18 '16 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.