2015-11-05 54 views
0

我如何在p標籤中添加文本?如何在e2e測試中添加iframe中的文本量角器

<div id="cke_1_contents" class="cke_contents cke_reset" role="presentation" style="height: 350px;"><span id="cke_44" class="cke_voice_label">Press ALT 0 for help</span> 
<iframe class="cke_wysiwyg_frame cke_reset" frameborder="0" src="" style="width: 100%; height: 100%;" title="Rich Text Editor, editor2" aria-describedby="cke_106" tabindex="0" allowtransparency="true"> 
<html lang="en" dir="ltr"> 
<head> 
    <body class="cke_editable cke_editable_themed cke_contents_ltr cke_show_borders" contenteditable="true" spellcheck="true"> 
    <p> 
    <br type="_moz"> 
    </p> 
</body> 
</html> 
</iframe> 
</div> 

我用這個代碼,但報錯

var p = element(by.css('.cke_editable p')); 
p.sendKeys('This is a peragraph tag'); 
+0

請過去的,你得到的錯誤那裏。 –

+0

css看起來不正確。它應該是'.cke_editable> p' –

+0

沒有再次發生同樣的錯誤發生沒有發現元素@PriyanshuShekhar –

回答

0

你需要切換到iframe的頁面上下文來做到這一點:

browser.switchTo().frame($('.cke_wysiwyg_frame')) 

var p = element(by.css('.cke_editable p')); 
p.sendKeys('This is a peragraph tag'); 

// switch back to the "parent page" context 
browser.switchTo().defaultContent() 
+0

最大調用堆棧大小超過這個錯誤ocurr –

+0

根據文檔,你必須指定一個iframe索引一個名稱/ id屬性。見https://angular.github.io/protractor/#/api?view=webdriver.WebDriver.TargetLocator.prototype.frame –

相關問題