如何成功运行此登录程序?

时间:2012-10-26 11:58:44

标签: webdriver

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( “用户名”))的SendKeys(用户名);

driver.findElement(By.id( “密码”))的SendKeys(密码)。

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

 }  

 public static void main(String[] args){ 

文件文件=新文件(“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"); 
   }
 }

我正在尝试登录Salesforce应用程序,但我的代码snipet无法正常工作。请提供帮助。

2 个答案:

答案 0 :(得分:1)

密码文本输入的ID是“password”而不是“pwd”。 要按“登录”按钮,您还应该使用其ID,即“登录”

答案 1 :(得分:0)

使用password代替pwdlogin代替login_button

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

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

此代码正确地为我工作

      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();   

}
      }