2016-09-21 52 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