0
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"); 
   }
 }

我正在尝试登录 Salesforce 应用程序,但我的这段代码不起作用。请帮助。

4

2 回答 2

1

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

于 2012-10-26T12:28:42.003 回答
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();   

}
      }
于 2012-10-29T10:59:41.403 回答