File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -209,6 +209,9 @@ self.switch_to_default_content()
209
209
210
210
self .switch_to_parent_frame()
211
211
212
+ with self .frame_switch(frame, timeout = None ):
213
+ # Indented Code Block for Context Manager (Must use "with")
214
+
212
215
self .set_content_to_frame(frame, timeout = None )
213
216
214
217
self .set_content_to_default(nested = False )
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ def test_anything(self):
42
42
import time
43
43
import unittest
44
44
import urllib3
45
+ from contextlib import contextmanager
45
46
from selenium.common.exceptions import (
46
47
ElementClickInterceptedException as ECI_Exception,
47
48
ElementNotInteractableException as ENI_Exception,
@@ -2775,6 +2776,18 @@ def switch_to_parent_frame(self):
2775
2776
return
2776
2777
self.driver.switch_to.parent_frame()
2777
2778
2779
+ @contextmanager
2780
+ def frame_switch(self, frame, timeout=None):
2781
+ """ Context Manager for switching into iframes.
2782
+ Usage example:
2783
+ with self.frame_switch("iframe"):
2784
+ # Perform actions here that should be done within the iframe.
2785
+ # The iframe is automatically exited after the "with" block ends.
2786
+ """
2787
+ self.switch_to_frame(frame, timeout=timeout)
2788
+ yield
2789
+ self.switch_to_parent_frame()
2790
+
2778
2791
def set_content_to_frame(self, frame, timeout=None):
2779
2792
"""Replaces the page html with an iframe's html from that page.
2780
2793
If the iframe contains an "src" field that includes a valid URL,
You can’t perform that action at this time.
0 commit comments