selenium处理rich text(富文本框)

WordPress 的 rich  text

采用js,先让selenium切换到iframe中

driver.switchTo().frame("content_ifr");

然后执行JS

WebElement editor = driver.findElement(By.tagName("body"));
   JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
   jsExecutor.executeScript("arguments[0].innerHTML = '

Selenium Test

I love Selenium
this article Post By Selenium WebDriver

Create By Young

'", editor);
   

为什么是innerHTML?

 

selenium处理rich text(富文本框)_第1张图片

 

最后再切换出iframe

  
   driver.switchTo().defaultContent();

 

 

 public void post()
  {
      //login();
      WebElement article=driver.findElement(By.xpath("//*[@id='menu-posts']/a/div[3]"));
      article.click();
      try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
      WebElement newArticle=driver.findElement(By.linkText("写文章"));
      newArticle.click();
      
      WebElement title=driver.findElement(By.xpath("//*[@id='title']"));
      title.sendKeys("I love Selenium");
      
      driver.switchTo().frame("content_ifr");
      WebElement editor = driver.findElement(By.tagName("body"));
      JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
      jsExecutor.executeScript("arguments[0].innerHTML = '

Selenium Test

I love Selenium
this article Post By Selenium WebDriver

Create By Young

'", editor); driver.switchTo().defaultContent(); WebElement submit =driver.findElement(By.xpath("//*[@id='publish']")); submit.click(); try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } WebElement check=driver.findElement(By.xpath("//*[@id='message']/p")); Assert.assertTrue(check.getText().contains("文章已发布")); }

 

你可能感兴趣的:(selenium处理rich text(富文本框))