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()=‘TestNg的IReporter接口的使用‘]")).click(); //博客园只能连续评论6次 for(int i = 0; i < 6; i++) { driver.findElement(By.id("tbCommentBody")).sendKeys("飞总,我来刷评论的"+i); driver.findElement(By.id("btn_comment_submit")).click(); driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); } } }
时间: 2024-11-12 14:56:25