selenium模拟登录wordpress并发布文章
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.List; /** * Created by zsn on 2015/3/25. */ public class WordpressDemo { public static void main(String[] args) { loginWordPress(); } private static void loginWordPress(){ WebDriver driver = new FirefoxDriver(); driver.get("http://www.apkfuns.com/wp-admin"); WebElement uid = driver.findElement(By.name("log")); WebElement pwd = driver.findElement(By.name("pwd")); WebElement btn = driver.findElement(By.id("wp-submit")); uid.sendKeys("****"); pwd.sendKeys("****"); btn.click(); //进入发布文章页面 driver.get("http://www.apkfuns.com/wp-admin/post-new.php"); //设置标题 WebElement postTitle = driver.findElement(By.id("title-prompt-text")); postTitle.sendKeys("this is title"); //设置发布的内容 String strMainHandler = driver.getWindowHandle(); WebElement iFrame = driver.findElements(By.className("ke-edit-iframe")).get(0); driver.switchTo().frame(iFrame); WebElement postSArea = driver.findElement(By.cssSelector("body.ke-content")); postSArea.sendKeys("12345"); driver.switchTo().window(strMainHandler); //涉及到iFrame操作参考 http://www.cnblogs.com/gzhu/archive/2012/12/24/2830731.html //选择分类目录 List<WebElement> categoryList = driver.findElements(By.cssSelector("#categorychecklist input[type='checkbox']")); categoryList.get(1).click(); //System.out.print("**"+list.size()); //输入tag driver.findElement(By.id("new-tag-post_tag")).sendKeys("custom tag"); driver.findElements(By.className("tagadd")).get(0).click(); //提交文章 driver.findElement(By.id("publish")).click(); } } |
转载请注明:软件测试 » selenium模拟登录wordpress并发布文章