在Selenium中访问动态生成的iframe的内容 [英] Access contents of dynamically generated iframe in Selenium
问题描述
我想使用XPath(或其他Selenium DSL定位器)来访问动态创建的 iframe
。我的目标是对动态iframe的内容做一些断言。
I want to use XPath (or other Selenium DSL locator) to access a dynamically created iframe
. My goal is to make some assertions about the contents of that dynamic iframe.
iframe
没有ID并且只有以下HTML属性:
The iframe
does not have an ID and has only the following HTML attributes:
src="javascript:""" style="position: absolute; left: -2000px;"
如果我能以某种方式选择那个 iframe
的框架,然后我可以 assertText
或使用XPath来测试 iframe
内部。
If I can somehow selectFrame that iframe
, then I can assertText
or use XPath to test the iframe
innards.
然而,简单的方法似乎失败了。由于某种原因, selectFrame(index = 0)
失败。也许我需要一些方法来 waitFor
要加载的 iframe
。但是我似乎无法为 iframe
创建定位器标识符,所以我不能 waitFor
它。
However, simple approaches seem to fail. The selectFrame("index=0")
fails for some reason. Perhaps I need some way to waitFor
the iframe
to be loaded. But I can't seem to create the locator identifier for the iframe
, so I can't waitFor
it.
推荐答案
您是否尝试过Selenium docs的这些提示?
Have you tried these tips from Selenium docs?
SelectFrame(locator)选择当前窗口中的帧。
(您可以多次调用此命令来选择嵌套帧。)
要选择父框架,请使用relative = parent作为定位器;到
选择顶部框架,使用relative = top。您也可以使用DOM
表达式直接识别您想要的帧,如下所示:
dom = frames [main]。frames [subframe]
SelectFrame ( locator ) Selects a frame within the current window. (You may invoke this command multiple times to select nested frames.) To select the parent frame, use "relative=parent" as a locator; to select the top frame, use "relative=top". You may also use a DOM expression to identify the frame you want directly, like this: dom=frames["main"].frames["subframe"]
http:/ /release.seleniumhq.org/selenium-core/0.8.0/reference.html
这篇关于在Selenium中访问动态生成的iframe的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!