Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda