Skip to content

Add a Context Manager method for switching into iframes using a "with" statement #1408

@mdmintz

Description

@mdmintz

Add a Context Manager method for switching into iframes using a with statement.

While inside the with block, the browser should be within the iframe control.

Here's an example test that should demonstrate this feature:

from seleniumbase import BaseCase

class FrameTests(BaseCase):
    def test_iframes_with_context_manager(self):
        self.open("https://seleniumbase.io/w3schools/iframes.html")
        with self.frame_switch("iframeResult"):
            self.assert_text("HTML Iframes", "h2")
            with self.frame_switch('[title*="Iframe"]'):
                self.assert_text("This page is displayed in an iframe", "h1")
            self.assert_text("Use CSS width & height to specify", "p")
            with self.frame_switch('[title*="Iframe"]'):
                self.assert_text("seleniumbase.io/w3schools/iframes", "a")
        self.click("button#runbtn")
        with self.frame_switch("iframeResult"):
            self.highlight('iframe[title="Iframe Example"]')

(Based on #1407)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions