Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

222
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda