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无法正常工作。请提供帮助。
答案 0 :(得分:1)
密码文本输入的ID是“password”而不是“pwd”。 要按“登录”按钮,您还应该使用其ID,即“登录”
答案 1 :(得分:0)
使用password
代替pwd
和login
代替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();
}
}