Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
How to write a selenium script so that the verification code will not be asked when logging in via Selenium?

If we have already logged into Salesforce in a browser and the user name, password is saved is there any way to keep the same so that when we are trying to login via Selenium script, the verification code will not be prompted?.

If I use the below code, it asks for a verification code:

browserdriver.get("https://slim4shady-dev-ed.my.salesforce.com");

browserdriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));

browserdriver.findElement(By.id("username")).sendKeys("xxxxxxx@gmail.com");

browserdriver.findElement(By.id("password")).sendKeys("xxxxxxx");

browserdriver.findElement(By.id("Login")).click();

Basically, I'm looking for a solution with the selenium script that uses the info from the previously logged in session or something so that the verification code will not be asked and that it shall directly log into Salesforce.

Please be noted that I'm trying not to add the IP as Trusted and use the browser capabilities (not sure if this is the term).

If you guys can help me with the solution for any one of the browser (Chrome preferably), that would be great.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Most websites track logged-in clients by assigning cookies to their browsers. Selenium gives the option to output client-assigned cookies to be later loaded in another browser session.

def export_cookies(driver):
    with open("cookies.txt", "w") as fd:
        fd.write(str(driver.get_cookies()))

def import_cookies(driver):
    with open("cookies.txt", "r") as fd:
        for cookie in eval(fd.read()):
            driver.add_cookie(cookie)

Export the cookies of a valid session that is logged in and fully verified with the code, and then import them while running your later attempts before loading the page. For most websites on loading the page, the client will send whatever cookies it has in its storage, and then the server will just instantly recognize the session and the client will load the logged-in page in the browser as normal.

Just make sure you export the cookies from a fully verified window, then load them before entering the website on a separate session. Do not change any other variables such as the client IP, user agent, driver, etc.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!