0
votes
import java.io.File;


public class LoginPage { 


private final WebDriver driver;  

  public LoginPage(WebDriver driver) {    

        this.driver = driver;  } 



public void loginAs(String username, String password) {  

 DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); 

ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);

// WebDriver driver = new InternetExplorerDriver(ieCapabilities);

driver.get("https://login.salesforce.com/?locale=uk");

driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);

driver.findElement(By.id("username")).sendKeys(username);

driver.findElement(By.id("password")).sendKeys(password);

driver.findElement(By.id("Login")).click();ogin.loginAs("username", "password");}}

 }  

 public static void main(String[] args){ 

File file = new File("C:/Users/E20039504/Desktop/Selenium Jar/IEDriverServer.exe");

System.setProperty("webdriver.ie.driver", file.getAbsolutePath());

LoginPage login = new LoginPage(new InternetExplorerDriver());

login.loginAs("username", "password"); 
   }
 }

I am trying to login to a Salesforce application but this code snipet of mine is not working.Kindly help.

2

2 Answers

1
votes

The Id of the password text input is "password" and not "pwd". To press to Login button, you should also use its Id, which is "Login"

0
votes

Used password instead of pwd and login instead of login_button

 driver.findElement(By.id("pwd")).sendKeys(password);   

 driver.findElement(By.className("Login_button")).click(); 

This code is work for me correctly

      public class login 
         {
public static void main(String[] args) 
 {
    DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); 
           ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
             WebDriver driver = new InternetExplorerDriver(ieCapabilities);          
             driver.get("https://login.salesforce.com/?locale=uk");

             try {
                Thread.sleep(4000);
            } catch (Exception e) {
                // TODO: handle exception
            }
             driver.findElement(By.id("username")).sendKeys("username");   
                     driver.findElement(By.id("password")).sendKeys("password");   
                     driver.findElement(By.id("Login")).click();   

}
      }