selenium实现自动登陆
System.setProperty("webdriver.chrome.driver", "C:/bin/chromedriver.exe");
WebDriver driver = new ChromeDriver();
String baseUrl = "https://passport.csdn.net/account/login"; // 加载url driver.get(baseUrl); // 等待加载完成 driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // 获取页面元素 WebElement elemUsername = driver.findElement(By.name("username"));
WebElement elemPassword = driver.findElement(By.name("password"));
WebElement btn = driver.findElement(By.className("logging"));
WebElement rememberMe = driver.findElement(By.id("rememberMe")); // 操作页面元素 elemUsername.clear();
elemPassword.clear();
elemUsername.sendKeys("username");
elemPassword.sendKeys("password");
rememberMe.click();
btn.click(); // 提交表单 //btn.submit(); Thread.sleep(5000); //driver.get("http://msg.csdn.net/"); Thread.sleep(5000); // 获取cookies //driver.manage().getCookies(); Set<org.openqa.selenium.Cookie> cookies = driver.manage().getCookies();
System.out.println("Size: " cookies.size());
Iterator<org.openqa.selenium.Cookie> itr = cookies.iterator();
CookieStore cookieStore = new BasicCookieStore(); while (itr.hasNext()) {
Cookie cookie = itr.next();
BasicClientCookie bcco = new BasicClientCookie(cookie.getName(), cookie.getValue());
bcco.setDomain(cookie.getDomain());
bcco.setPath(cookie.getPath());
cookieStore.addCookie(bcco);
}
资源文件列表
BlockChain/.classpath , 1276
BlockChain/.project , 1086
BlockChain/.settings/.jsdtscope , 639
BlockChain/.settings/org.eclipse.core.resources.prefs , 162
BlockChain/.settings/org.eclipse.jdt.core.prefs , 430
BlockChain/.settings/org.eclipse.ltk.core.refactoring.prefs , 106
BlockChain/.settings/org.eclipse.m2e.core.prefs , 90
BlockChain/.settings/org.eclipse.m2e.wtp.prefs , 86
BlockChain/.settings/org.eclipse.wst.common.component , 597
BlockChain/.settings/org.eclipse.wst.common.project.facet.core.xml , 292
BlockChain/.settings/org.eclipse.wst.jsdt.ui.superType.container , 49
BlockChain/.settings/org.eclipse.wst.jsdt.ui.superType.name , 6
BlockChain/.settings/org.eclipse.wst.validation.prefs , 50
BlockChain/.settings/org.eclipse.wst.ws.service.policy.prefs , 87
BlockChain/pom.xml , 1617
BlockChain/src/main/java/tech/topcoder/blockchain/Block.java , 2615
BlockChain/src/main/java/tech/topcoder/blockchain/BlockChain.java , 9382
BlockChain/src/main/java/tech/topcoder/blockchain/DateUtil.java , 24868
BlockChain/src/main/java/tech/topcoder/blockchain/InitListener.java , 406
BlockChain/src/main/webapp/answer.jsp , 1517
BlockChain/src/main/webapp/chain.jsp , 309
BlockChain/src/main/webapp/detail.jsp , 1822
BlockChain/src/main/webapp/index.jsp , 1502
BlockChain/src/main/webapp/js/jquery-1.10.2.js , 93113
BlockChain/src/main/webapp/login.jsp , 614
BlockChain/src/main/webapp/sync.jsp , 566
BlockChain/src/main/webapp/WEB-INF/web.xml , 757
BlockChain/target/classes/tech/topcoder/blockchain/Block.class , 2749
BlockChain/target/classes/tech/topcoder/blockchain/BlockChain.class , 8925
BlockChain/target/classes/tech/topcoder/blockchain/DateUtil.class , 12757
BlockChain/target/classes/tech/topcoder/blockchain/InitListener.class , 679
BlockChain/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF , 105
BlockChain/target/m2e-wtp/web-resources/META-INF/maven/tech.topcoder/blockchain/pom.properties , 239
BlockChain/target/m2e-wtp/web-resources/META-INF/maven/tech.topcoder/blockchain/pom.xml , 1617
