Access contents of dynamically generated iframe in Selenium

北城余情 提交于 2020-01-02 03:23:29

问题


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.

The iframe does not have an ID and has only the following HTML attributes:

src="javascript:""" style="position: absolute; left: -2000px;"

If I can somehow selectFrame that iframe, then I can assertText or use XPath to test the iframe innards.

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.


回答1:


Have you tried these tips from Selenium docs?

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



来源:https://stackoverflow.com/questions/4321921/access-contents-of-dynamically-generated-iframe-in-selenium

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!