zoukankan      html  css  js  c++  java
  • 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 = '<h1>Selenium Test </h1>I love Selenium <br> this article Post By Selenium WebDriver<br><h2>Create By Young</h2>'", editor);
       

    为什么是innerHTML?

    最后再切换出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 = '<h1>Selenium Test </h1>I love Selenium <br> this article Post By Selenium WebDriver<br><h2>Create By Young</h2>'", 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("文章已发布"));
         
      }
  • 相关阅读:
    ubuntu重新安装mysql
    linux基本命令
    ubuntu启用root用户
    cada的常规使用
    如果有人对我的mysql的笔记感兴趣请联系我,互相学习
    10、mysql查看进程
    09、Mysql 查询是否锁表
    08、查看锁记录等待时间:
    针对发送网络附件的java方法(使用Apache的jar包调用)
    mysql的卸载重装+导入大量数据失败的解决方案+工具执行和项目执行结果不同
  • 原文地址:https://www.cnblogs.com/tobecrazy/p/3947086.html
Copyright © 2011-2022 走看看