@@ -2569,9 +2569,9 @@ def switch_to_frame(self, frame, timeout=None):
25692569
25702570 def switch_to_default_content(self):
25712571 """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. """
25752575 self.__check_scope()
25762576 if self.recorder_mode and self._rec_overrides_switch:
25772577 url = self.get_current_url()
@@ -2589,18 +2589,39 @@ def switch_to_default_content(self):
25892589 return
25902590 self.driver.switch_to.default_content()
25912591
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+
25922614 def set_content_to_frame(self, frame, timeout=None):
25932615 """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,
25952617 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.
25972619 To return to default content, use: self.set_content_to_default().
25982620 This method also sets the state of the browser window so that the
25992621 self.set_content_to_default() method can bring the user back to
26002622 the original content displayed, which is similar to how the methods
26012623 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."""
26042625 self.__check_scope()
26052626 if not timeout:
26062627 timeout = settings.SMALL_TIMEOUT
@@ -2663,12 +2684,12 @@ def set_content_to_frame(self, frame, timeout=None):
26632684 action = ["s_c_f", o_frame, origin, time_stamp]
26642685 self.__extra_actions.append(action)
26652686
2666- def set_content_to_default(self, nested=True ):
2687+ def set_content_to_default(self, nested=False ):
26672688 """After using self.set_content_to_frame(), this reverts the page back.
26682689 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. """
26722693 self.__check_scope()
26732694 swap_cnt = self.execute_script("return document.cframe_swap;")
26742695 tab_sta = self.execute_script("return document.cframe_tab;")
@@ -2679,7 +2700,10 @@ def set_content_to_default(self, nested=True):
26792700 action = ["sk_op", "", origin, time_stamp]
26802701 self.__extra_actions.append(action)
26812702
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.
26832707 if (
26842708 len(self.__page_sources) > 0
26852709 and (
@@ -2705,6 +2729,9 @@ def set_content_to_default(self, nested=True):
27052729 self.execute_script("document.cframe_swap = 0;")
27062730 self.__page_sources = []
27072731 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.
27082735 just_refresh = False
27092736 if swap_cnt and int(swap_cnt) > 0 and len(self.__page_sources) > 0:
27102737 self.execute_script("document.cframe_swap -= 1;")
@@ -2736,6 +2763,24 @@ def set_content_to_default(self, nested=True):
27362763 action = ["s_c_d", nested, origin, time_stamp]
27372764 self.__extra_actions.append(action)
27382765
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+
27392784 def open_new_window(self, switch_to=True):
27402785 """Opens a new browser tab/window and switches to it by default."""
27412786 self.__check_scope()
@@ -3643,6 +3688,7 @@ def __process_recorded_actions(self):
36433688 ext_actions.append("as_et")
36443689 ext_actions.append("sw_fr")
36453690 ext_actions.append("sw_dc")
3691+ ext_actions.append("sw_pf")
36463692 ext_actions.append("s_c_f")
36473693 ext_actions.append("s_c_d")
36483694 ext_actions.append("sh_fc")
@@ -3878,6 +3924,8 @@ def __process_recorded_actions(self):
38783924 sb_actions.append("self.%s('%s')" % (method, action[1]))
38793925 elif action[0] == "sw_dc":
38803926 sb_actions.append("self.switch_to_default_content()")
3927+ elif action[0] == "sw_pf":
3928+ sb_actions.append("self.switch_to_parent_frame()")
38813929 elif action[0] == "s_c_f":
38823930 method = "set_content_to_frame"
38833931 if '"' not in action[1]:
@@ -3888,9 +3936,10 @@ def __process_recorded_actions(self):
38883936 method = "set_content_to_default"
38893937 nested = action[1]
38903938 if nested:
3939+ method = "set_content_to_parent"
38913940 sb_actions.append("self.%s()" % method)
38923941 else:
3893- sb_actions.append("self.%s(nested=False )" % method)
3942+ sb_actions.append("self.%s()" % method)
38943943 elif action[0] == "as_el":
38953944 method = "assert_element"
38963945 if '"' not in action[1]:
@@ -7001,7 +7050,7 @@ def add_slide(
70017050 image - Attach an image (from a URL link) to the slide.
70027051 code - Attach code of any programming language to the slide.
70037052 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.
70057054 content2 - HTML content to display after adding an image or code.
70067055 notes - Additional notes to include with the slide.
70077056 ONLY SEEN if show_notes is set for the presentation.
0 commit comments