2016-09-21 53 views
0

我是新来的这两个的CKEditor以及硒 那么Web应用程序中,我的工作是类似于CKEDITOR选择文本

我已经写了通过硒在那里我的代码在编辑器中输入文本,但现在我的要求是选择我输入的所有文本。 我无法选择该文本。 任何人都知道它的解决方案。请让我知道。

WebElement iframe1 = driver.findElement(By.tagName("iframe")); 
    driver.switchTo().frame(iframe1); 
    WebElement web1=driver.findElement(By.xpath("//div[@class='p']")); 
    web1.clear(); 
    Actions act1=new Actions(driver); 
    act1.sendKeys(web1, "Hello"); 
+0

看看这个 - http://stackoverflow.com/questions/18319547/why-sendkeyskeys-chordkeys-control-a-does-not-work-in-chrome – Grasshopper

回答

0

我只是想选择编辑器中的内容,这样我可以使用格式工具栏格式化这些文本

你应该尝试如下选择从编辑器中的所有文本内容: -

import org.openqa.selenium.Keys; 

WebDriverWait wait = new WebDriverWait(driver, 10); 

wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe.cke_wysiwyg_frame.cke_reset"))); 

WebElement body = wait.until(ExpectedConditions.visibilityOfElementLocated(By.tagName("body"))); 

//Now select all text content from editor 
body.sendKeys(Keys.chord(Keys.CONTROL, "a")) 

//Now after entering text into texteditor switch back to default content 
driver.switchTo().defaultContent(); 

//Now perform action to format the text content