Fix Windows bug in UC Mode for uc_gui_handle_cf()

This commit is contained in:
Michael Mintz 2024-06-30 21:26:44 -04:00
parent 3dbaf41e93
commit 2655d10018
2 changed files with 16 additions and 6 deletions

View File

@ -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)

View File

@ -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
)
@ -1442,7 +1446,12 @@ 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().
@ -1450,6 +1459,7 @@ def switch_to_window(driver, window, timeout=settings.SMALL_TIMEOUT):
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
@ -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
@ -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