如何在iframe下处理#document [英] Ways to deal with #document under iframe

查看:968
本文介绍了如何在iframe下处理#document的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我现在正在测试的门户网站,我遇到的问题是我无法创建任何xpath定位器,经过一段时间我发现它是因为'#document',这会削减路径并简化复制xpath将路径指向完全不同的元素。

For the portal I am testing now, I came with the problem that I could not create any xpath locators, after some time I figured out that it was because of an '#document', this cuts the path and makes the simple "copy xpath" to direct the path to a completely different element.

<iframe id="FRAMENAME" src="/webclient/workspace/launch-task/REMbl?ds=BP" width="100%" height="100%" frameborder="0" data-navitemname="navitemname" style="" xpath="1">
#document
    <html>
        CODE....
    </html>

我找到了解决方法它只是添加一个开关,如下所示:

I found the solution for this is it is simply add a switchTo like this:

driver.switchTo().frame("FRAMENAME");

这样可以使其余的代码正常工作,但需要一些额外的时间来处理这个命令直到代码移到下一行。

This works and makes the rest of the code to work properly but, takes some extra time processing this command till the code moves to the next line.

所以我想问一下,有没有更好的解决方案呢?更聪明/更快的东西?

So I would like to ask, is there is a better solution for this? something smarter/faster?

我担心当我有大量脚本出现时,执行时间会花费太长时间。

I am concerned that when the point where I have lots of scripts comes, the execution time will take too long.

我不使用id定位器,因为它们都是动态的,所以有时需要xpath。

I don't use id locators for example because they are all dynamic so sometimes a xpath is required.

谢谢!

推荐答案

内嵌框架



根据使用内联框架,内联框架是一种将文档嵌入HTML文档的构造,以便嵌入数据是显示在浏览器窗口的子窗口内。这并不意味着完全包含,这两个文件是独立的,它们都被视为完整的文件,而不是将其作为另一个文件的一部分。

inline frames

As per the documentation in Using inline frames, an inline frame is a construct which embeds a document into an HTML document so that embedded data is displayed inside a subwindow of the browser's window. This does not mean full inclusion and the two documents are independent, and both them are treated as complete documents, instead of treating one as part of the other.


  • 通常,iframe元素的格式为:

  • Generally, an iframe element is in the form of:

<iframe src="URL" more attributes>
alternative content for browsers which do not
support iframe
</iframe>


  • 支持iframe的浏览器显示子窗口中URL引用的文档,通常带有垂直和/或水平滚动条。此类浏览器会忽略iframe元素的内容(即开始标记< iframe ...> 和结束标记< /之间的所有内容的iframe> )。不支持iframe(或禁用此类支持)的浏览器则相反,即处理内容,就好像< iframe ...> < / iframe> 标签不存在。因此,尽管被一些浏览器忽略,但内容很重要。

  • Browsers which support iframe display the document referred to by the URL in a subwindow, typically with vertical and/or horizontal scroll bars. Such browsers ignore the content of the iframe element (i.e. everything between the start tag <iframe...> and the end tag </iframe>). Browsers which do not support iframe (or have such support disabled) does the opposite, i.e. process the content as if the <iframe...> and </iframe> tags were not there. Thus, the content matters, despite being ignored by some browsers.

    总而言之,内联框架并不意味着包含功能,尽管它有时可能会用于类似目的。

    So to summarize, inline frames do not mean an include feature, although it might sometimes serve similar purposes.

    请注意,当使用内联框架时,浏览器(如果它支持它们)会向 iframe元素中的URL ,并在获取所请求的文档后将其显示在内联框架内。从这个意义上说,内联框架是一个联合的浏览器 - 服务器问题,但只有浏览器需要具体的iframe感知;从服务器的角度来看,文档只有一个普通的HTTP请求,它发送文档时没有(或者不需要)知道浏览器将用它做什么。

    Note that, when inline frames are used, the browser (if it supports them) sends a request to the server referred to by the URL in the iframe element, and after getting the requested document displays it inside an inline frame. In this sense inline frames are a joint browser-server issue, but only the browser needs to be specifically iframe-aware; from the server's point of view, there's just a normal HTTP request for a document, and it sends the document without having (or needing) any idea on what the browser is going to do with it.

    按照<切换到 iframe 时,您需要按以下方式引导 WebDriverWait

    As per the best practices while switching to an iframe you need to induce WebDriverWait as follows:


    • 切换框架名称(Java示例代码):

    • Switch through Frame Name (Java Sample Code):

    new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.name("frame_name")));
    


  • 您可以在是否可以切换到框架中的元素而不使用Selenium中的driver.switchTo()。frame(frameName) Webdriver Java?

    内嵌框架与普通框架

    这篇关于如何在iframe下处理#document的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆