简体   繁体   English

在编写iFrame时需要帮助

[英]Need help in writing into an iFrame

I am facing issues in writing into iframe, I am able to identify the iframe but I am not able to write anything into the frame. 我在写入iframe时遇到问题,我能够识别iframe,但无法在框架中写入任何内容。 Whenever I try to write into the frame I am getting below error. 每当我尝试写入框架时,都会遇到错误。

org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 211 milliseconds
Build info: version: '2.43.1', revision: '5163bce', time: '2014-09-10 16:27:33'

This is the screenshot of my HTML Code. 是我的HTML代码的屏幕截图。

HTML Snippet: HTML片段:

<div id="offer_description_field" class="control-group wysihtml5_type description_field ">
    <label class="control-label" for="offer_description">
        Description
    </label>
    <div class="controls well">
        <ul class="wysihtml5-toolbar" style="">
        <textarea id="offer_description" class="bootstrap-wysihtml5ed" rows="3" name="offer[description]" data-richtext="bootstrap-wysihtml5" data-options="{"csspath":"/assets/bootstrap-wysihtml5.css","jspath":"/assets/bootstrap-wysihtml5.js","config_options":"null"}" cols="48" style="display: none;"></textarea>
        <input type="hidden" name="_wysihtml5_mode" value="1">
        <iframe class="wysihtml5-sandbox" width="0" height="0" frameborder="0" security="restricted" allowtransparency="true" marginwidth="0" marginheight="0" style="display: inline-block; background-color: rgb(255, 255, 255); border-collapse: separate; border-color: rgb(204, 204, 204); border-style: solid; border-width: 1px; clear: none; float: none; margin: 0px; outline: 0px none rgb(0, 0, 0); outline-offset: 0px; padding: 4px 6px; position: static; z-index: auto; vertical-align: middle; text-align: start; box-sizing: content-box; box-shadow: 0px 1px 1px 0px rgba(0, 0, 0, 0.075) inset; border-radius: 4px; width: 327.8px; height: 60px; top: auto; left: auto; right: auto; bottom: auto;"></iframe>
        <p class="help-block">Required. Add offer description.</p>
    </div>
</div>

When I create a simple HTML file with above code snippet I am not able to interact with element. 当我使用上述代码片段创建一个简单的HTML文件时,无法与element进行交互。 Manually I am able to write anything inside this iframe when it is coming with full code base. 当它具有完整的代码库时,我可以手动在此iframe中编写任何内容。 Looks like it is replacing the textarea with iframe. 看起来它正在用iframe代替textarea。 Not sure how to deal with this type of element. 不知道如何处理这种类型的元素。

This is how it appears on the panel. 就是它在面板上的显示方式。

Can anybody help? 有人可以帮忙吗?

you should takecare of following things while working with frames : 1.Select the frame . 使用框架时,应注意以下事项:1.选择框架。 then enter into the text/textarea. 然后输入文本/文本区域。 Note: sometimes the elements are not in the visible area in the UI hence we may required to take the element into view port , following below code spinet before entering into the text/textarea : WebElement element = driver.findElement(By.id("id_of_element")); 注意:有时元素不在UI的可见区域中,因此在输入文本/文本区域之前,我们可能需要按照下面的代码小节将元素带入查看端口:WebElement element = driver.findElement(By.id(“ id_of_element“)); ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element); (((JavascriptExecutor)驱动程序).executeScript(“ arguments [0] .scrollIntoView(true);”,元素);

2.then deselect the frame . 2.然后取消选择框架。

Hope this would work for you . 希望这对您有用。

This error doesn't have to do with the IFRAME . 此错误与IFRAME无关。 In fact, the element you are interacting with isn't inside the IFRAME. 实际上,您要与之交互的元素不在IFRAME中。 The reason you can't interact with it is stated in the error. 错误中指出了您无法与其互动的原因。

org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与之交互

The element is not visible. 该元素不可见。 If you look at the TEXTAREA element, it is marked with style="display: none;" 如果您查看TEXTAREA元素,则将其标记为style="display: none;" which is why it is not visible. 这就是为什么它不可见的原因。 Selenium was designed to interact with the page as a user would and so will not interact with hidden elements. Selenium旨在与用户交互,因此不会与隐藏元素交互。 You will need to approach this problem as a user would... how would a user get that text area to appear? 您将需要像用户一样解决此问题。用户将如何显示该文本区域? I'm assuming click something, etc. You will need your script to execute whatever a user would do, then the TEXTAREA will become visible, and will be able to be interacted with. 我假设单击了某物,等等。您将需要您的脚本来执行用户将要执行的任何操作,然后TEXTAREA将变得可见,并且可以与之交互。

Switch into that iframe either by id/class using following code 使用以下代码按id/class切换到该iframe

driver.switchTo().frame(driver.findElement(By.id("Enter id of element")));

OR 要么

driver.switchTo().frame(driver.findElement(By.class("Enter class of element")));

Once you switched to the frame select the element with your normal steps. 切换到框架后,请按照常规步骤选择元素。 like 喜欢

driver.findelement(By.id/class/css/xpath("Enter Element id/class/css/xpath"));

Then, if you want to select any other element from the main frame, simply go back to your main frame with following code 然后,如果要从主框架中选择任何其他元素,只需使用以下代码返回主框架

driver.switchTo().defaultContent();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM