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.
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().
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With