Update CDP Mode

This commit is contained in:
Michael Mintz 2024-12-03 18:01:18 -05:00
parent 667602c4e8
commit ac26b08942
4 changed files with 29 additions and 5 deletions

View File

@ -606,6 +606,9 @@ def uc_open_with_cdp_mode(driver, url=None):
cdp.click_nth_element = CDPM.click_nth_element
cdp.click_nth_visible_element = CDPM.click_nth_visible_element
cdp.click_link = CDPM.click_link
cdp.go_back = CDPM.go_back
cdp.go_forward = CDPM.go_forward
cdp.get_navigation_history = CDPM.get_navigation_history
cdp.tile_windows = CDPM.tile_windows
cdp.get_all_cookies = CDPM.get_all_cookies
cdp.set_all_cookies = CDPM.set_all_cookies
@ -1419,11 +1422,8 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
page_actions.switch_to_window(
driver, driver.current_window_handle, 2, uc_lock=False
)
if (
IS_WINDOWS
and hasattr(pyautogui, "getActiveWindowTitle")
):
py_a_g_title = pyautogui.getActiveWindowTitle()
if IS_WINDOWS and hasattr(pyautogui, "getActiveWindowTitle"):
py_a_g_title = pyautogui.getActiveWindowTitle() or ""
window_title = driver.get_title()
if not py_a_g_title.startswith(window_title):
window_rect = driver.get_window_rect()

View File

@ -289,6 +289,15 @@ class CDPMethods():
def click_link(self, link_text):
self.find_elements_by_text(link_text, "a")[0].click()
def go_back(self):
self.loop.run_until_complete(self.page.back())
def go_forward(self):
self.loop.run_until_complete(self.page.forward())
def get_navigation_history(self):
return self.loop.run_until_complete(self.page.get_navigation_history())
def __clear_input(self, element):
return (
self.loop.run_until_complete(element.clear_input_async())

View File

@ -1323,6 +1323,9 @@ class BaseCase(unittest.TestCase):
def go_back(self):
self.__check_scope()
if self.__is_cdp_swap_needed():
self.cdp.go_back()
return
if hasattr(self, "recorder_mode") and self.recorder_mode:
self.save_recorded_actions()
pre_action_url = None
@ -1348,6 +1351,9 @@ class BaseCase(unittest.TestCase):
def go_forward(self):
self.__check_scope()
if self.__is_cdp_swap_needed():
self.cdp.go_forward()
return
if hasattr(self, "recorder_mode") and self.recorder_mode:
self.save_recorded_actions()
self.__last_page_load_url = None
@ -1732,6 +1738,9 @@ class BaseCase(unittest.TestCase):
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
timeout = self.__get_new_timeout(timeout)
partial_link_text = self.__get_type_checked_text(partial_link_text)
if self.__is_cdp_swap_needed():
self.cdp.find_element(partial_link_text, timeout=timeout).click()
return
if not self.is_partial_link_text_present(partial_link_text):
self.wait_for_partial_link_text_present(
partial_link_text, timeout=timeout
@ -8133,6 +8142,8 @@ class BaseCase(unittest.TestCase):
def is_chromium(self):
"""Return True if the browser is Chrome or Edge."""
self.__check_scope()
if self.__is_cdp_swap_needed():
return True
chromium = False
if (
"chrome" in self.driver.capabilities

View File

@ -636,6 +636,10 @@ class Tab(Connection):
"""History forward"""
await self.send(cdp.runtime.evaluate("window.history.forward()"))
async def get_navigation_history(self):
"""Get Navigation History"""
return await self.send(cdp.page.get_navigation_history())
async def reload(
self,
ignore_cache: Optional[bool] = True,