Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 356
Dave Viner Avatar asked Dec 01 '10 06:12

Dave Viner


People also ask

How do you handle dynamic web elements?

One more way to handle dynamic element is to find all elements with Tag name and search required element by contains text value or element attributes. For example, to search button with specific text you can use below code: IList webElement = BrowserDriver. GetDriver().

How do you handle nested frames?

In the case of nested frames, At first we must switch to the outer frame by either Index or ID of the iframe. Once we switch to the outer frame we can find the total number of iframes inside the outer frame, and. We can switch to the inner frame by any of the known methods.


1 Answers

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

like image 101
Rajasankar Avatar answered Oct 11 '22 14:10

Rajasankar