selenium 跳转问题
要实现一个网站(www.koudai.com)的淘宝登陆,目前想实现的逻辑是鼠标移登陆 点击淘宝登陆跳转到淘宝登陆页输入账号 密码再授权,登陆成功 目前只考虑第一次登陆(即每次都要输入密码)首页KoudaiIndexPage 类入下:
public class KoudaiIndexPage {
private WebDriver driver;
private final String url="http://www.koudai.com/";
public KoudaiIndexPage(WebDriver driver){
this.driver=driver;
driver.get(url);
}
//实现鼠标移并跳转到登陆页面
public WebDriver openLoginPage(WebDriver driver){
Actions a= new Actions(driver) ;
a.moveToElement(driver.findElement(By.xpath("//div[@id='J_cornerLogin' and @class='float-left']/span[@class='float-left pointer']"))).perform();
driver.findElement(By.className("corner-login-taobao")).click();
//driver.switchTo().defaultContent();
System.out.println("pageSource>>"+driver.getPageSource());
return driver;
}
//授权
public AuthorizeLogin authorize(WebDriver driver) throws Exception{
this.login(driver, "honger08240129","a123456");
driver.switchTo().defaultContent();
driver.findElement(By.id("sub")).click();
return new AuthorizeLogin(driver);
}
//登陆
public TaoBaoLogin login(WebDriver driver,String username,String passwd) throws Exception{
this.openLoginPage(driver);
WebDriverWait wait=new WebDriverWait(driver,10);
wait.until(new ExpectedCondition<WebElement>(){
@Override
public WebElement apply(WebDriver dr) {
return dr.findElement(By.id("TPL_username_1"));
}}).clear();
System.out.println("pageSource>>"+driver.getPageSource());
//driver.findElement(By.id("TPL_username_1")).clear();
driver.findElement(By.id("TPL_username_1")).sendKeys("honger08240129");
driver.findElement(By.id("TPL_password_1")).clear();
driver.findElement(By.id("TPL_password_1")).sendKeys("a123456");
driver.findElement(By.id("J_SubmitStatic")).click();
return new TaoBaoLogin(driver);
}
TaoBaoLogin 类如下:
public class TaoBaoLogin {
private WebDriver driver;
public TaoBaoLogin(WebDriver driver){
this.driver=driver;
}
public String getTitle(){
return driver.getTitle();
}
public String getContent(){
return driver.getPageSource();
}
}
AuthorizeLogin 类如下:
public class AuthorizeLogin {
private WebDriver driver;
publicAuthorizeLogin(WebDriver driver){
this.driver=driver;
}
public String getTitle(){
return driver.getTitle();
}
public String getContext(){
return driver.getPageSource();
}
}
目前能跳转到淘宝登陆页但是在运行到openLoginPage(WebDriver driver)这个方法提示:org.openqa.selenium.WebDriverException: Unable to get browser (WARNING: The server did not provide any stacktrace information) 在“openLoginPage”使用selectWindow方法试试。
页:
[1]