简体   繁体   中英

How to login into Salesforce (Chrome) application using selenium webdriver and avoid identity verification)

I try login to Salesforce whit this script, but it launches the page of verification of identity. The user and password are working, so how can I avoid the verification page?

WebDriver driver = new ChromeDriver();
driver.get("https://test.salesforce.com/");
driver.manage().window().maximize();
Thread.sleep(3000);
//login
driver.findElement(By.id("username")).sendKeys("xxxxx");
Thread.sleep(1000);
driver.findElement(By.id("password")).sendKeys("xxx");
Thread.sleep(1000);
driver.findElement(By.id("Login")).click();
driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);

To avoid identity verification, you can go to the Salesforce organization you're using and mark your IP as trusted. Once you do that, you will be able to log in without two-factor authentication for all future test runs (as long as they use the same IP).

To mark your IP as trusted, go to Setup - Security Controls - Network Access.

To login into the Salesforce Web Application as the AUT is based on Lazy Loading you have to induce WebDriverWait for the elements to be clickable as follows:

driver.get("https://test.salesforce.com/");
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.input.username#username"))).sendKeys("RodrigoC");
driver.findElement(By.cssSelector("input.input.password#password")).sendKeys("RodrigoC");
driver.findElement(By.cssSelector("input.button.wide.primary")).click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM