@@ -2569,9 +2569,9 @@ def switch_to_frame(self, frame, timeout=None):
2569
2569
2570
2570
def switch_to_default_content(self):
2571
2571
"""Brings driver control outside the current iframe.
2572
- ( If the driver control is inside an iframe, the driver control
2573
- will be set to one level above the current frame. If the driver
2574
- control is not currently in an iframe, nothing will happen.) """
2572
+ If the driver is currently set inside an iframe or nested iframes,
2573
+ then the driver control will exit from all entered iframes.
2574
+ If the driver is not currently set in an iframe, nothing happens. """
2575
2575
self.__check_scope()
2576
2576
if self.recorder_mode and self._rec_overrides_switch:
2577
2577
url = self.get_current_url()
@@ -2589,18 +2589,39 @@ def switch_to_default_content(self):
2589
2589
return
2590
2590
self.driver.switch_to.default_content()
2591
2591
2592
+ def switch_to_parent_frame(self):
2593
+ """Brings driver control outside the current iframe.
2594
+ If the driver is currently set inside an iframe or nested iframes,
2595
+ the driver control will be set to one level above the current frame.
2596
+ If the driver is not currently set in an iframe, nothing happens."""
2597
+ self.__check_scope()
2598
+ if self.recorder_mode and self._rec_overrides_switch:
2599
+ url = self.get_current_url()
2600
+ if url and len(url) > 0:
2601
+ if ("http:") in url or ("https:") in url or ("file:") in url:
2602
+ r_a = self.get_session_storage_item("recorder_activated")
2603
+ if r_a == "yes":
2604
+ self.__set_c_from_switch = True
2605
+ self.set_content_to_default(nested=True)
2606
+ self.__set_c_from_switch = False
2607
+ time_stamp = self.execute_script("return Date.now();")
2608
+ origin = self.get_origin()
2609
+ action = ["sw_pf", "", origin, time_stamp]
2610
+ self.__extra_actions.append(action)
2611
+ return
2612
+ self.driver.switch_to.parent_frame()
2613
+
2592
2614
def set_content_to_frame(self, frame, timeout=None):
2593
2615
"""Replaces the page html with an iframe's html from that page.
2594
- If the iFrame contains an "src" field that includes a valid URL,
2616
+ If the iframe contains an "src" field that includes a valid URL,
2595
2617
then instead of replacing the current html, this method will then
2596
- open up the "src" URL of the iFrame in a new browser tab.
2618
+ open up the "src" URL of the iframe in a new browser tab.
2597
2619
To return to default content, use: self.set_content_to_default().
2598
2620
This method also sets the state of the browser window so that the
2599
2621
self.set_content_to_default() method can bring the user back to
2600
2622
the original content displayed, which is similar to how the methods
2601
2623
self.switch_to_frame(frame) and self.switch_to_default_content()
2602
- work together to get the user into frames and out of all of them.
2603
- """
2624
+ work together to get the user into frames and out of all of them."""
2604
2625
self.__check_scope()
2605
2626
if not timeout:
2606
2627
timeout = settings.SMALL_TIMEOUT
@@ -2663,12 +2684,12 @@ def set_content_to_frame(self, frame, timeout=None):
2663
2684
action = ["s_c_f", o_frame, origin, time_stamp]
2664
2685
self.__extra_actions.append(action)
2665
2686
2666
- def set_content_to_default(self, nested=True ):
2687
+ def set_content_to_default(self, nested=False ):
2667
2688
"""After using self.set_content_to_frame(), this reverts the page back.
2668
2689
If self.set_content_to_frame() hasn't been called here, only refreshes.
2669
- If "nested" is set to False when the content was set to nested iFrames ,
2670
- then the control will only move above the last iFrame that was entered.
2671
- """
2690
+ If "nested" is set to True when the content is set to a nested iframe ,
2691
+ then the page control will only exit from the current iframe entered,
2692
+ instead of exiting out of all iframes entered. """
2672
2693
self.__check_scope()
2673
2694
swap_cnt = self.execute_script("return document.cframe_swap;")
2674
2695
tab_sta = self.execute_script("return document.cframe_tab;")
@@ -2679,7 +2700,10 @@ def set_content_to_default(self, nested=True):
2679
2700
action = ["sk_op", "", origin, time_stamp]
2680
2701
self.__extra_actions.append(action)
2681
2702
2682
- if nested:
2703
+ if not nested:
2704
+ # Sets the page to the outer-most content.
2705
+ # If page control was inside nested iframes, exits them all.
2706
+ # If only in one iframe, has the same effect as nested=True.
2683
2707
if (
2684
2708
len(self.__page_sources) > 0
2685
2709
and (
@@ -2705,6 +2729,9 @@ def set_content_to_default(self, nested=True):
2705
2729
self.execute_script("document.cframe_swap = 0;")
2706
2730
self.__page_sources = []
2707
2731
else:
2732
+ # (If Nested is True)
2733
+ # Sets the page to the content outside the current nested iframe.
2734
+ # If only in one iframe, has the same effect as nested=True.
2708
2735
just_refresh = False
2709
2736
if swap_cnt and int(swap_cnt) > 0 and len(self.__page_sources) > 0:
2710
2737
self.execute_script("document.cframe_swap -= 1;")
@@ -2736,6 +2763,24 @@ def set_content_to_default(self, nested=True):
2736
2763
action = ["s_c_d", nested, origin, time_stamp]
2737
2764
self.__extra_actions.append(action)
2738
2765
2766
+ def set_content_to_default_content(self, nested=False):
2767
+ """Same as self.set_content_to_default()."""
2768
+ self.set_content_to_default(nested=nested)
2769
+
2770
+ def set_content_to_parent(self):
2771
+ """Same as self.set_content_to_parent_frame().
2772
+ Same as self.set_content_to_default(nested=True).
2773
+ Sets the page to the content outside the current nested iframe.
2774
+ Reverts self.set_content_to_frame()."""
2775
+ self.set_content_to_default(nested=True)
2776
+
2777
+ def set_content_to_parent_frame(self):
2778
+ """Same as self.set_content_to_parent().
2779
+ Same as self.set_content_to_default(nested=True).
2780
+ Sets the page to the content outside the current nested iframe.
2781
+ Reverts self.set_content_to_frame()."""
2782
+ self.set_content_to_default(nested=True)
2783
+
2739
2784
def open_new_window(self, switch_to=True):
2740
2785
"""Opens a new browser tab/window and switches to it by default."""
2741
2786
self.__check_scope()
@@ -3643,6 +3688,7 @@ def __process_recorded_actions(self):
3643
3688
ext_actions.append("as_et")
3644
3689
ext_actions.append("sw_fr")
3645
3690
ext_actions.append("sw_dc")
3691
+ ext_actions.append("sw_pf")
3646
3692
ext_actions.append("s_c_f")
3647
3693
ext_actions.append("s_c_d")
3648
3694
ext_actions.append("sh_fc")
@@ -3878,6 +3924,8 @@ def __process_recorded_actions(self):
3878
3924
sb_actions.append("self.%s('%s')" % (method, action[1]))
3879
3925
elif action[0] == "sw_dc":
3880
3926
sb_actions.append("self.switch_to_default_content()")
3927
+ elif action[0] == "sw_pf":
3928
+ sb_actions.append("self.switch_to_parent_frame()")
3881
3929
elif action[0] == "s_c_f":
3882
3930
method = "set_content_to_frame"
3883
3931
if '"' not in action[1]:
@@ -3888,9 +3936,10 @@ def __process_recorded_actions(self):
3888
3936
method = "set_content_to_default"
3889
3937
nested = action[1]
3890
3938
if nested:
3939
+ method = "set_content_to_parent"
3891
3940
sb_actions.append("self.%s()" % method)
3892
3941
else:
3893
- sb_actions.append("self.%s(nested=False )" % method)
3942
+ sb_actions.append("self.%s()" % method)
3894
3943
elif action[0] == "as_el":
3895
3944
method = "assert_element"
3896
3945
if '"' not in action[1]:
@@ -7001,7 +7050,7 @@ def add_slide(
7001
7050
image - Attach an image (from a URL link) to the slide.
7002
7051
code - Attach code of any programming language to the slide.
7003
7052
Language-detection will be used to add syntax formatting.
7004
- iframe - Attach an iFrame (from a URL link) to the slide.
7053
+ iframe - Attach an iframe (from a URL link) to the slide.
7005
7054
content2 - HTML content to display after adding an image or code.
7006
7055
notes - Additional notes to include with the slide.
7007
7056
ONLY SEEN if show_notes is set for the presentation.
0 commit comments