码迷,mamicode.com
首页 > Web开发 > 详细

使用Webdriver刷飞总博客文章评论

时间:2015-05-20 13:05:13      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

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);
		}
	}
}

 

使用Webdriver刷飞总博客文章评论

标签:

原文地址:http://www.cnblogs.com/jaychang/p/4516796.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!