Я новичок в селене. Я пытаюсь вставить добавить текст в разделе INSERT HTML HERE
. Код:
<iframe src="" frameborder="0" class="cke_wysiwyg_frame cke_reset" style="width: 100%; height: 100%;" title="editor, postContent" aria-describedby="cke_93" tabindex="0" allowtransparency="true">
#document
<html dir="rtl" lang="he">
<head>
<title data-cke-title="editor, postContent">editor, postContent</title>
<style data-cke-temp="1">html{cursor:text;*cursor:auto}
img,input,textarea{cursor:default}
</style>
<link type="text/css" rel="stylesheet" href="[SOME_URL]/Blogs/ckeditor/contents.css?t=F969">
<style data-cke-temp="1">.cke_editable{cursor:text}.cke_editable img,.cke_editable input,.cke_editable textarea{cursor:default}
img.cke_flash{background-image: url([SOME_URL]/Blogs/ckeditor/plugins/flash/images/placeholder.png?t=F969);background-position: center center;background-repeat: no-repeat;border: 1px solid #a9a9a9;width: 80px;height: 80px;}
.cke_editable form{border: 1px dotted #FF0000;padding: 2px;}
img.cke_hidden{background-image: url([SOME_URL]/Blogs/ckeditor/plugins/forms/images/hiddenfield.gif?t=F969);background-position: center center;background-repeat: no-repeat;border: 1px solid #a9a9a9;width: 16px !important;height: 16px !important;}
img.cke_iframe{background-image: url([SOME_URL]/Blogs/ckeditor/plugins/iframe/images/placeholder.png?t=F969);background-position: center center;background-repeat: no-repeat;border: 1px solid #a9a9a9;width: 80px;height: 80px;}
.cke_contents_ltr a.cke_anchor,.cke_contents_ltr a.cke_anchor_empty,.cke_editable.cke_contents_ltr a[name],.cke_editable.cke_contents_ltr a[data-cke-saved-name]{background:url([SOME_URL]/Blogs/ckeditor/plugins/link/images/anchor.png?t=F969) no-repeat left center;border:1px dotted #00f;background-size:16px;padding-left:18px;cursor:auto;}.cke_contents_ltr img.cke_anchor{background:url([SOME_URL]/Blogs/ckeditor/plugins/link/images/anchor.png?t=F969) no-repeat left center;border:1px dotted #00f;background-size:16px;width:16px;min-height:15px;height:1.15em;vertical-align:text-bottom;}.cke_contents_rtl a.cke_anchor,.cke_contents_rtl a.cke_anchor_empty,.cke_editable.cke_contents_rtl a[name],.cke_editable.cke_contents_rtl a[data-cke-saved-name]{background:url([SOME_URL]/Blogs/ckeditor/plugins/link/images/anchor.png?t=F969) no-repeat right center;border:1px dotted #00f;background-size:16px;padding-right:18px;cursor:auto;}.cke_contents_rtl img.cke_anchor{background:url([SOME_URL]/Blogs/ckeditor/plugins/link/images/anchor.png?t=F969) no-repeat right center;border:1px dotted #00f;background-size:16px;width:16px;min-height:15px;height:1.15em;vertical-align:text-bottom;}
div.cke_pagebreak{background:url([SOME_URL]/Blogs/ckeditor/plugins/pagebreak/images/pagebreak.gif?t=F969) no-repeat center center !important;clear:both !important;width:100% !important;border-top:#999 1px dotted !important;border-bottom:#999 1px dotted !important;padding:0 !important;height:7px !important;cursor:default !important;}
.cke_show_blocks h6:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks h5:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks h4:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks h3:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks h2:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks h1:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks blockquote:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks address:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks pre:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks div:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks p:not([contenteditable=false]):not(.cke_show_blocks_off){background-repeat:no-repeat;border:1px dotted gray;padding-top:8px}.cke_show_blocks h6:not([contenteditable=false]):not(.cke_show_blocks_off){background-image:url([SOME_URL]/Blogs/ckeditor/plugins/showblocks/images/block_h6.png?t=F969)}.cke_show_blocks h5:not([contenteditable=false]):not(.cke_show_blocks_off){background-image:url([SOME_URL]/Blogs/ckeditor/plugins/showblocks/images/block_h5.png?t=F969)}.cke_show_blocks h4:not([contenteditable=false]):not(.cke_show_blocks_off){background-image:url([SOME_URL]/Blogs/ckeditor/plugins/showblocks/images/block_h4.png?t=F969)}.cke_show_blocks h3:not([contenteditable=false]):not(.cke_show_blocks_off){background-image:url([SOME_URL]/Blogs/ckeditor/plugins/showblocks/images/block_h3.png?t=F969)}.cke_show_blocks h2:not([contenteditable=false]):not(.cke_show_blocks_off){background-image:url([SOME_URL]/Blogs/ckeditor/plugins/showblocks/images/block_h2.png?t=F969)}.cke_show_blocks h1:not([contenteditable=false]):not(.cke_show_blocks_off){background-image:url([SOME_URL]/Blogs/ckeditor/plugins/showblocks/images/block_h1.png?t=F969)}.cke_show_blocks blockquote:not([contenteditable=false]):not(.cke_show_blocks_off){background-image:url([SOME_URL]/Blogs/ckeditor/plugins/showblocks/images/block_blockquote.png?t=F969)}.cke_show_blocks address:not([contenteditable=false]):not(.cke_show_blocks_off){background-image:url([SOME_URL]/Blogs/ckeditor/plugins/showblocks/images/block_address.png?t=F969)}.cke_show_blocks pre:not([contenteditable=false]):not(.cke_show_blocks_off){background-image:url([SOME_URL]/Blogs/ckeditor/plugins/showblocks/images/block_pre.png?t=F969)}.cke_show_blocks div:not([contenteditable=false]):not(.cke_show_blocks_off){background-image:url([SOME_URL]/Blogs/ckeditor/plugins/showblocks/images/block_div.png?t=F969)}.cke_show_blocks p:not([contenteditable=false]):not(.cke_show_blocks_off){background-image:url([SOME_URL]/Blogs/ckeditor/plugins/showblocks/images/block_p.png?t=F969)}.cke_show_blocks.cke_contents_ltr h6:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_ltr h5:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_ltr h4:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_ltr h3:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_ltr h2:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_ltr h1:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_ltr blockquote:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_ltr address:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_ltr pre:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_ltr div:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_ltr p:not([contenteditable=false]):not(.cke_show_blocks_off){background-position:top left;padding-left:8px}.cke_show_blocks.cke_contents_rtl h6:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_rtl h5:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_rtl h4:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_rtl h3:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_rtl h2:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_rtl h1:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_rtl blockquote:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_rtl address:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_rtl pre:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_rtl div:not([contenteditable=false]):not(.cke_show_blocks_off),.cke_show_blocks.cke_contents_rtl p:not([contenteditable=false]):not(.cke_show_blocks_off){background-position:top right;padding-right:8px}
.cke_show_borders table.cke_show_border,.cke_show_borders table.cke_show_border > tr > td, .cke_show_borders table.cke_show_border > tr > th,.cke_show_borders table.cke_show_border > tbody > tr > td, .cke_show_borders table.cke_show_border > tbody > tr > th,.cke_show_borders table.cke_show_border > thead > tr > td, .cke_show_borders table.cke_show_border > thead > tr > th,.cke_show_borders table.cke_show_border > tfoot > tr > td, .cke_show_borders table.cke_show_border > tfoot > tr > th{border : #d3d3d3 1px dotted}
.cke_upload_uploading img{opacity: 0.3}
.cke_widget_wrapper{position:relative;outline:none}.cke_widget_inline{display:inline-block}.cke_widget_wrapper:hover>.cke_widget_element{outline:2px solid yellow;cursor:default}.cke_widget_wrapper:hover .cke_widget_editable{outline:2px solid yellow}.cke_widget_wrapper.cke_widget_focused>.cke_widget_element,.cke_widget_wrapper .cke_widget_editable.cke_widget_editable_focused{outline:2px solid #ace}.cke_widget_editable{cursor:text}.cke_widget_drag_handler_container{position:absolute;width:15px;height:0;left:-9999px;opacity:0.75;transition:height 0s 0.2s;line-height:0}.cke_widget_wrapper:hover>.cke_widget_drag_handler_container{height:15px;transition:none}.cke_widget_drag_handler_container:hover{opacity:1}img.cke_widget_drag_handler{cursor:move;width:15px;height:15px;display:inline-block}.cke_widget_mask{position:absolute;top:0;left:0;width:100%;height:100%;display:block}.cke_editable.cke_widget_dragging, .cke_editable.cke_widget_dragging *{cursor:move !important}
</style>
</head>
<body contenteditable="true" class="cke_editable cke_editable_themed cke_contents_rtl cke_show_borders" spellcheck="false">INSERT HTML HERE</body>
</html>
</iframe>
Я пытаюсь понять, как использовать селен с iframe. Я уже видел довольно много предыдущих тем, но не мог понять из них, как решить мою конкретную проблему c. Похоже, html должен быть вставлен в тег body
, который находится в теге iframe
. Я хочу, чтобы iframe отображал HTML. Я пытался:
body = driver.find_element_by_class_name("cke_editable")
Но получил:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".cke_editable"}
Как мне это сделать?
РЕДАКТИРОВАТЬ : Я, вероятно, должен был объяснить выпускать лучше. Текстовое поле выглядит следующим образом:

Если я использую текстовое поле, не нажимая кнопку Source
, тогда, если я вставлю HTML это будет относиться к нему как к тексту. Но если я переключусь в режим Source
и вставлю HTML, а затем go из режима Source
, то отобразится HTML. Код, который я показал выше, это когда я не в исходном коде. @ 0buz предложил мне:
iframe=driver.find_element_by_xpath("//iframe[@title='editor, postContent']")
driver.switch_to.frame(iframe)
body=driver.find_element_by_xpath("//body[@contenteditable='true']")
driver.execute_script("arguments[0].innerText = 'INSERT HTML HERE'", body)
И это сработало! Но он вставил текст и для HTML не работает. Когда я переключаюсь в режим Source
, я получаю:
<div id="cke_74_contents" class="cke_contents cke_reset" role="presentation" style="height: 350px;">
<textarea dir="ltr" class="cke_source cke_reset cke_enable_context_menu cke_editable cke_editable_themed cke_contents_rtl" style="width: 100%; height: 100%; resize: none; outline: none; text-align: left; tab-size: 4;" tabindex="0" role="textbox" aria-label="editor, postContent" title="editor, postContent" aria-describedby="cke_165"></textarea>
<span id="cke_165" class="cke_voice_label">Press</span>
</div>
Но если я ввожу текст, когда я в режиме Source
, он не отображается в исходном коде Chrome, где он быть измененным Только когда я в режиме non-source
показывает, что этот текст находится в теле. Моя цель - вставить HTML, а не текст. Есть ли способ добиться этого?