Selenium webdriver没有登录到live.com

时间:2014-05-24 20:15:48

标签: java selenium selenium-webdriver

我一直在尝试使用Selenium Webdriver登录live.com但是每次尝试都会导致无效的电子邮件或密码。使用正确的登录。我在物理浏览器中测试过它。我不确定是否是这种情况,但我相信sendkeys不起作用。代码如下。

protected static Map<String,String> settings = new HashMap<String,String>();
public static WebDriver pwb;

在Main:

    // Default settings
    settings.put("browser","chrome");
    settings.put("os","WINDOWS8");


    // Sort arguments and put into HashMap
    grab(args);

    // Set browser settings
    DesiredCapabilities cap = DesiredCapabilities.htmlUnitWithJs();
    cap.setBrowserName(settings.get("browser"));
    cap.setPlatform(Platform.extractFromSysProperty(settings.get("os")));
    d.log(cap.asMap().toString());

    // Create web browser object
    pwb = new HtmlUnitDriver(cap);

    login();

在登录()中:

Load("http://login.live.com",0); // custom load function
d.log(pwb.getTitle());
if(pwb.getTitle().contains("Sign in to your")){ // Full login
            d.log("Executing full login.\nEmail:" + settings.get("email") + "\nPassword:"+settings.get("password"));
//              if (pwb instanceof JavascriptExecutor) {
//                  ((JavascriptExecutor) pwb).executeScript("document.getElementsByName('login')[0].click();"); //value = " + settings.get("email") + "");
//                  ((JavascriptExecutor) pwb).executeScript("document.getElementsByName('passwd')[0].click();"); //.value = " + settings.get("password") + "");
//              }
            // TODO get login working
            pwb.findElement(By.id("i0116")).clear();
            pwb.findElement(By.id("i0116")).sendKeys(settings.get("email"));
            pwb.findElement(By.id("i0118")).clear();
            pwb.findElement(By.id("i0118")).sendKeys(settings.get("password"));
            pwb.findElement(By.name("SI")).click();
            // Attempted = true;
        }

如果需要更多信息,请告诉我。

0 个答案:

没有答案