Skip to content

Commit c6e8748

Browse files
committed
Only "bring_active_window_to_front()" if not in a frame
1 parent 1a4f4ff commit c6e8748

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3939,12 +3939,18 @@ def __are_quotes_escaped(self, string):
39393939
def __escape_quotes_if_needed(self, string):
39403940
return js_utils.escape_quotes_if_needed(string)
39413941

3942+
def __is_in_frame(self):
3943+
return js_utils.is_in_frame(self.driver)
3944+
39423945
def bring_active_window_to_front(self):
39433946
"""Brings the active browser window to the front.
39443947
This is useful when multiple drivers are being used."""
39453948
self.__check_scope()
39463949
try:
3947-
self.switch_to_window(self.driver.current_window_handle)
3950+
if not self.__is_in_frame():
3951+
# Only bring the window to the front if not in a frame
3952+
# because the driver resets itself to default content.
3953+
self.switch_to_window(self.driver.current_window_handle)
39483954
except Exception:
39493955
pass
39503956

seleniumbase/fixtures/js_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,24 @@ def escape_quotes_if_needed(string):
212212
return string
213213

214214

215+
def is_in_frame(driver):
216+
"""
217+
Returns True if the driver has switched to a frame.
218+
Returns False if the driver was on default content.
219+
"""
220+
return driver.execute_script(
221+
"""
222+
var frame = window.frameElement;
223+
if (frame) {
224+
return true;
225+
}
226+
else {
227+
return false;
228+
}
229+
"""
230+
)
231+
232+
215233
def safe_execute_script(driver, script):
216234
"""When executing a script that contains a jQuery command,
217235
it's important that the jQuery library has been loaded first.

0 commit comments

Comments
 (0)