Dave Viner
Dave Viner

Reputation: 539

Access contents of dynamically generated iframe in Selenium

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.

Upvotes: 6

Views: 5521

Answers (1)

Rajasankar
Rajasankar

Reputation: 928

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

Upvotes: 6

Related Questions