课程: Test Automation with Selenium WebDriver for Java

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

iFrames

iFrames

- [Instructor] Iframes are web elements that allow a webpage to display content from another webpage. For example, this iframe has embedded click_iframe.html. Notice this iframe contains a link. Normally we would use WebDriver to locate this link in the DOM so that we can click it. However iframes include the DOM of the page that is embedded. So what we have here are two DOMs. In order to interact with an element within an iframe, we need to switch to the DOM within the frame. To switch to the iframe's context, we call driver.switchTo.frame. And we can pass in the iframe's ID or name to this method. The iframe's ID is ifr. If the iframe did not contain an ID or name attribute, you could also provide an index where zero is the top level DOM and the iframe's DOM would be at index one. Alternatively, you could use any locator strategy to find the iframe web element and pass that in. Okay, now we're in the DOM of the page that the iframe contains and can interact with any of its elements.…

内容