java – Selenium WebDriver:无法使用TinyMCE编辑器在iframe中
发布时间:2020-12-15 04:28:16 所属栏目:Java 来源:网络整理
导读:也许我的问题类似于这个 Selenium WebDriver cannot locate element within an iframe,and throws NoSuchElementException但是我仍然找不到必需的元素. 元素本身看起来: body id="tinymce" class="mceContentBody" contenteditable="true" onload="window.p
也许我的问题类似于这个
Selenium WebDriver cannot locate element within an iframe,and throws NoSuchElementException但是我仍然找不到必需的元素.
元素本身看起来: body id="tinymce" class="mceContentBody" contenteditable="true" onload="window.parent.tinyMCE.get('compose_295_composeEditor').onLoad.dispatch();" dir="ltr" style="overflow: auto;"> 包含此元素的iframe是: body id="tinymce" class="mceContentBody" contenteditable="true" onload="window.parent.tinyMCE.get('compose_295_composeEditor').onLoad.dispatch();" dir="ltr" style="overflow: auto;"> 我试过了 driver.switchTo().frame(10); driver.switchTo().frame(driver.findElement(By.id("tinymce"))); driver.findElement(By.id("tinymce")).clear(); driver.findElement(By.id("tinymce")).sendKeys("Privet!"); // clear mail text body driver.switchTo().defaultContent(); 但收到错误: Unable to locate frame: 10 尝试过类似的东西 driver.switchTo().frame(driver.findElement(By.id("tinymce"))); 如其他答案所述,但收到NoSuchElement错误. 元素周围的HTML是: <div class="b-compose__editor ru_RU"> <div id="compose_295_toolbar_external" class="compose__editor_toolbar defaultSkin"> <div class="js-removeDraftContainer infobar infobar_notice infobar_draft" style="display: none;"> <div id="compose_295_composeFrame" class="b-compose__editor__frame"> <div class="compose__editor__frame_shadow"></div> <table class="w100" cellspacing="0" cellpadding="0"> <tbody> <tr> <td class="vti w100"> <div id="compose_295_composeEditorFrame" class="composeEditorFrame" style="height: 200px;"> <table id="compose_295_shell__text" class="mlruTmpId0" cellspacing="0" cellpadding="0" bgcolor="" background="" style="width: 100%"> <tbody> <tr class="nojsdn textModeHide"> <tr> <td class="cell w100"> <table id="compose_295_middleTable" class="w100" cellspacing="0" cellpadding="0"> <tbody> <tr id="compose_295_middleRow_sht"> <td id="compose_295_shell__text_cell_holder" class="cell shell__text_cell_holder w100" valign="top"> <table class="w100" cellspacing="0" cellpadding="0"> <tbody> <tr class="nojsdn textModeHide"> <tr> <td id="compose_295_shell__text_cell" class="cell shell__text_cell w100" valign="top"> <textarea id="compose_295_composeEditor" class="bsbb composeEditor" wrap="physical" tabindex="10" name="Body" style="width: 100%; height: 570px; display: none;" cols="80" rows="15" spellcheck="true" aria-hidden="true"> </textarea> <span id="compose_295_composeEditor_parent" class="mceEditor defaultSkin"> <table id="compose_295_composeEditor_tbl" class="mceLayout" cellspacing="0" cellpadding="0" style="width: 100%; height: 570px;"> <tbody> <tr class="mceFirst mceLast"> <td class="mceIframeContainer mceFirst mceLast"> <iframe id="compose_295_composeEditor_ifr" frameborder="0" src="javascript:""" allowtransparency="true" title="{#aria.rich_text_area}" style="width: 100%; height: 200px; display: block;" hidefocus="true" tabindex="10" scrolling="auto"> <html> <head xmlns="http://www.w3.org/1999/xhtml"> <body id="tinymce" class="mceContentBody" contenteditable="true" onload="window.parent.tinyMCE.get('compose_295_composeEditor').onLoad.dispatch();" dir="ltr" style="overflow: auto;"> </html> </iframe> </td> </tr> </tbody> </table> </span> </td> </tr> <tr class="nojsdn textModeHide"> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> UPD Selenium and wordpress: New post test,olyv的回答帮助了我,但是: 解决方法
根据html,识别iframe的选择器是不正确的.我正在使用一个cssSelector,它允许您识别具有部分id匹配的iframe.你为什么不尝试这个?
driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[id$='_composeEditor_ifr']"))); d?r?i?v?e?r?.?s?w?i?t?c?h?T?o?(?)?.?f?r?a?m?e?(?d?r?i?v?e?r?.?f?i?n?d?E?l?e?m?e?n?t?(?B?y?.?i?d?(?"?t?i?n?y?m?c?e?"?)?)?)?;? driver.findElement(By.id("tinymce")).clear(); driver.findElement(By.id("tinymce")).sendKeys("Privet!"); // clear mail text body driver.switchTo().defaultContent(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |