2013-04-19 1 views
0

webdriver를 사용하여 귀여운 편집기와 상호 작용할 수있는 방법을 알고있는 사람이 있습니까? 나는 그 문안을 깨끗하게하고 싶습니까?webdriver를 사용하여 귀여운 편집기와 상호 작용

<iframe id="CE_Editor1_ID_Frame" src="cuteeditor_files/template.asp" 
frameborder="0" class="CuteEditorFrame CuteEditorFrame" 
style="background-color: white; border: 1px solid rgb(221, 221, 221); 
height: 100%; width: 100%; display: block;"></iframe> 

아래 코드는 작동하지 않습니까?

driver.switchTo().frame(0); 
driver.switchTo().activeElement().clear(); 
+0

입력 영역의 'id'는 무엇입니까? 그걸 정리 해봐. – Amey

답변

0

나는 지금은 iframe이가 '텍스트 영역'이기 때문에 당신이 대신 텍스트 영역/입력을 찾고의 driver.switchTo().activeElement()을 사용하는 이유를 이해하고, 당신이 내 모든 것을 지우려면, http://cutesoft.net/example/general.aspx에서 귀여운 편집기의 데모를 살펴했다 iframe

나는 당신이 데모

<iframe id="CE_Editor1_ID_Frame" src="cuteeditor_files/template.asp" frameborder="0" class="CuteEditorFrame CuteEditorFrame" style="background-color: white; border: 1px solid rgb(221, 221, 221); height: 100%; width: 100%; display: block;"> 
    <html> 
     <head></head> 
     <body> 
      <table>the real stuff in the editor, you want to clear this, right?</table> 
      <br> 
      <br> 
     </body> 
    </html> 
</iframe> 

내가 셀레늄이 노드를 삭제하는 것을 제공합니다 생각하지 않습니다 유사하다 가정,하지만 당신은 JavascriptExecutor하여이 작업을 수행 할 수 있습니다. 경고 : 테스트되지 않은 코드, 논리 만 있습니다. 당신은 약간 자신을 디버깅해야합니다.

// first try to avoid switching frames by index, unless you have no other ways. 

// if you have only one frame with class name CuteEditorFrame 
WebElement editorFrame = driver.findElement(By.cssSelector(".CuteEditorFrame")); 
driver.switchTo().frame(editorFrame); 

// if the id 'CE_Editor1_ID_Frame' not dynamic 
WebElement editorFrame = driver.findElement(By.cssSelector("#CE_Editor1_ID_Frame")); 
driver.switchTo().frame(editorFrame); // driver.switchTo().frame("CE_Editor1_ID_Frame"); 

// then remove everything inside the iframe's body 
JavascriptExecutor js; 
if (driver instanceof JavascriptExecutor) { 
    js = (JavascriptExecutor)driver; 
} 
WebElement editorBody = driver.findElement(By.cssSelector("body")); 
js.executeScript("arguments[0].innerHTML = ''", editorBody); 

// alternatively, using sendKeys directly is a better way 
WebElement body = driver.findElement(By.tagName("body")); // then you find the body 
body.sendKeys(Keys.CONTROL + "a"); // send 'ctrl+a' to select all 
body.SendKeys("Some text");