switchFrame
Switches the active context to a frame, e.g. an iframe on the page. There are multiple ways you can query a frame on the page:
-
If given a string it switches to the frame with a matching context id, url or url that contains that string
// switch to a frame that has the url "https://the-internet.herokuapp.com/iframe"
await browser.switchFrame('https://the-internet.herokuapp.com/iframe')
// switch to a frame that has a certain context id
await browser.switchFrame('A5734774C41F8C91D483BDD4022B2EF3') -
If given a WebdriverIO element that references an
iframe
element it will switch to that frame// switch to a frame element queried from current context
await browser.switchFrame($('iframe')) -
If given a function it will loop through all iframes on the page and call the function with the context object. The function should return a boolean indicating if the frame should be selected. Within the function you can use WebdriverIO commands to e.g. check if a certain frame element exists.
// switch to first frame that contains an element with id "#frameContent"
await browser.switchFrame(() => $('#frameContent').isExisting()) -
If given
null
it will switch to the top level frame// first switch into a frame
await browser.switchFrame($('iframe'))
// do more automation within that frame, then ...
// switch to the top level frame
await browser.switchFrame(null)
Usage
browser.switchFrame(context)
Parameters
Name | Type | Details |
---|---|---|
context | string , object , function |