Skip to content

Commit

Permalink
Merge pull request #2890 from seleniumbase/fix-windows-bug-in-uc-mode
Browse files Browse the repository at this point in the history
Fix Windows thread-locking bug in UC Mode
  • Loading branch information
mdmintz authored Jul 1, 2024
2 parents 3dbaf41 + 74cb173 commit 1c526f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.28.2"
__version__ = "4.28.3"
2 changes: 1 addition & 1 deletion seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ def uc_gui_handle_cf(driver, frame="iframe"):
if not is_in_frame:
# Make sure the window is on top
page_actions.switch_to_window(
driver, driver.current_window_handle, 2
driver, driver.current_window_handle, 2, uc_lock=False
)
if not is_in_frame or needs_switch:
# Currently not in frame (or nested frame outside CF one)
Expand Down
20 changes: 15 additions & 5 deletions seleniumbase/fixtures/page_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,8 +1430,12 @@ def switch_to_frame(driver, frame, timeout=settings.SMALL_TIMEOUT):
timeout_exception(Exception, message)


def __switch_to_window(driver, window_handle):
if hasattr(driver, "_is_using_uc") and driver._is_using_uc:
def __switch_to_window(driver, window_handle, uc_lock=True):
if (
hasattr(driver, "_is_using_uc")
and driver._is_using_uc
and uc_lock
):
gui_lock = fasteners.InterProcessLock(
constants.MultiBrowser.PYAUTOGUILOCK
)
Expand All @@ -1442,14 +1446,20 @@ def __switch_to_window(driver, window_handle):
return True


def switch_to_window(driver, window, timeout=settings.SMALL_TIMEOUT):
def switch_to_window(
driver,
window,
timeout=settings.SMALL_TIMEOUT,
uc_lock=True,
):
"""
Wait for a window to appear, and switch to it. This should be usable
as a drop-in replacement for driver.switch_to.window().
@Params
driver - the webdriver object (required)
window - the window index or window handle
timeout - the time to wait for the window in seconds
uc_lock - if UC Mode and True, switch_to_window() uses thread-locking
"""
if window == -1:
window = len(driver.window_handles) - 1
Expand All @@ -1465,7 +1475,7 @@ def switch_to_window(driver, window, timeout=settings.SMALL_TIMEOUT):
shared_utils.check_if_time_limit_exceeded()
try:
window_handle = driver.window_handles[window]
__switch_to_window(driver, window_handle)
__switch_to_window(driver, window_handle, uc_lock=uc_lock)
return True
except IndexError:
now_ms = time.time() * 1000.0
Expand All @@ -1486,7 +1496,7 @@ def switch_to_window(driver, window, timeout=settings.SMALL_TIMEOUT):
for x in range(int(timeout * 10)):
shared_utils.check_if_time_limit_exceeded()
try:
__switch_to_window(driver, window_handle)
__switch_to_window(driver, window_handle, uc_lock=uc_lock)
return True
except NoSuchWindowException:
now_ms = time.time() * 1000.0
Expand Down

0 comments on commit 1c526f1

Please sign in to comment.