2012-10-26 65 views
0
public class LoginPage { 
    private final WebDriver driver; 
    public LoginPage(WebDriver driver) 
    {  
     this.driver = driver; 
    } 
    public void loginAs(String username, String password) 
    { 
     /* driver.get("https://login.salesforce.com/?locale=uk"); 
     driver.manage().timeouts().implicitlyWait(05, TimeUnit.SECONDS); 
     System.out.println("READ"); 
     // System.out.println(driver.findElement(By.id("pwcaps")).getText()); 
     //driver.findElement(By.id(username)).sendKeys("sambit"); 
     //driver.findElement(By.className(password)).sendKeys("PWD"); 
     //driver.findElement(By.id(username)).sendKeys("Password"); 
     /*if (driver.findElement(By.className("loginButton")).isEnabled()) 
     { 
     System.out.println("entered If loop"); 
     System.out.println("login Button is enabled"); 
     driver.findElement(By.className("loginButton")).click(); 
     } 
     else 
     { 
     driver.close(); 
     }*/ 
     if (driver.findElement(By.id("Account_Tab")).isEnabled()) 
     { 
     System.out.println("Account tab is enabled"); 
     } 
     else 
     { 
     System.out.println("Account tab is not enabled"); 
     } 
    } 
    public static void main(String[] args){ 
     // TODO Auto-generated method stub 

     LoginPage login = new LoginPage(new InternetExplorerDriver()); 
     login.loginAs("sambit.sabyasachi", "check"); 
    } 

该网页显示,这个领域不启用形式如何使用selenium webdriver登录到Salesforce应用程序?

+0

我试图运行这个snipet,但问题是我的脚本不能到saleforce输入用户名和pwd application.The报表已经评论突出显示他们 – user1776382

回答

0

的自动灌装尝试以下登录功能。

public void login(String username, String password){ 
    driver.findElement(By.name("username")).sendKeys(username); 
    driver.findElement(By.cssSelector("input[type='password']")).sendKeys(password); 
    driver.findElement(By.cssSelector("input[type='submit']")).click(); 
} 

我不确定一旦你登录了你的意图,但是这对我们基于salesforce的应用程序测试很有用。

你会调用加载了登录页面后,此功能。

+0

我试过了,但这也不适合我。我目前正在使用IE8。以下是错误消息:无法找到与CSS选择元件==输入[类型=“密码”](警告:服务器没有提供任何堆栈跟踪信息) – user1776382

+0

我只是复制这个从实时销售人员登录屏幕。 <输入类= “txtbox辉光” 类型= “密码” ID = “密码” 名称= “PW” 大小= “18” 自动填充= “关闭” onkeypress事件= “checkCaps(事件)”> 如果它是类似于Salesforce登录屏幕的密码字段所使用的HTML,那么您可以使用上述名称,ID或CSS选择器。如果它不起作用,那么你能告诉我你的测试代码吗? – haroonzone

1

请检查该代码它的工作对我罚款

public class login 
    { 
    public static void main(String[] args) 
     { 
     DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); 
        ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); 

      WebDriver iedriver = new InternetExplorerDriver(ieCapabilities); 
      iedriver.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(); 

} 
    } 
相关问题