selenium向富文本框填写内容的几种方式

富文本框如果是iframe,则用下

1.先跳转到irame,dr.switchTo().frame(wtext);

然后用js

JavascriptExecutor jsExecutor = (JavascriptExecutor) dr;
jsExecutor.executeScript("arguments[0].innerHTML = '<p align=\"center\"><strong>钜计划协议</strong></p>'", dr.findElement(By.xpath("/html/body")));

2.用sendkeys

        dr.findElement(By.xpath("/html/body")).sendKeys(s);

 

如果是源码格式,如下图

 

思路是先点击源码,然后在sendkeys

WebElement wym = BrowserOptions.fFind(dr, By.xpath("/html/body/div[3]/div[2]/div/div/form/table/tbody/tr[4]/td/span/span[2]/span/table/tbody/tr[1]/td/div/span[2]/span[3]/span[1]/a/span[2]"));
wym.click();

//WebElement wtext = dr.findElement(By.id("cke_contents_content")).findElement(By.xpath("/html/body/div[3]/div[2]/div/div/form/table/tbody/tr[4]/td/span/span[2]/span/table/tbody/tr[2]/td/textarea"));
//wtext.sendKeys(s);

posted on 2015-06-09 11:46  乔叶叶  阅读(3922)  评论(0编辑  收藏  举报

导航