package com.zhc.webdriver;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.TimeUnit; import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait; public class feizong { public static void main(String[] args) {
// TODO Auto-generated method stub System.setProperty("webdriver.firefox.bin", "F:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); ProfilesIni ini = new ProfilesIni(); FirefoxProfile profile = ini.getProfile("default"); WebDriver driver = new FirefoxDriver(profile); driver.get("http://www.cnblogs.com/");
driver.manage().window().maximize(); driver.findElement(By.xpath("//a[text()='登录']")).click(); //博客园账号
driver.findElement(By.id("input1")).sendKeys("xxxxxx"); //博客园密码
driver.findElement(By.id("input2")).sendKeys("xxxxxx"); driver.findElement(By.id("signin")).click(); WebDriverWait wait = new WebDriverWait(driver, 5); //登录的账号名
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[text()='南风_real']"))); driver.get("http://www.cnblogs.com/zhangfei"); //要评论的文章名标题
driver.findElement(By.xpath("//a[text()='JAVA MD5加密']")).click(); ArrayList<String> list = new ArrayList<String>(); list.add("文章内容不错");
list.add("感谢分享");
list.add("飞总好牛逼");
list.add("非常好的内容");
list.add("又学到东西了");
list.add("继续加油"); Iterator<String> iter = list.iterator(); while (iter.hasNext()) {
driver.findElement(By.id("tbCommentBody")).sendKeys(iter.next());
driver.findElement(By.id("btn_comment_submit")).click();
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
} }
}
05-11 17:52