From e3f8dc1bd678c53b0f46d107bfaf7d4253806519 Mon Sep 17 00:00:00 2001 From: joao-voltarelli Date: Tue, 12 Aug 2025 12:07:32 -0300 Subject: [PATCH 1/4] TEST: Adjusting Edge setup --- conftest.py | 16 +++++++++++++++- tests/test_browser.py | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/conftest.py b/conftest.py index f8ab517..2f3ccc3 100644 --- a/conftest.py +++ b/conftest.py @@ -120,7 +120,21 @@ def download_driver(request): manager = factory_driver_manager(browser=browser) cache_manager = DriverCacheManager(root_dir=folder_driver) - installed_driver = manager(cache_manager=cache_manager).install() + + if browser == Browser.EDGE: + # The Edge webdriver download link has changed. + # Since the webdriver-manager is using the outdated link, it is necessary to pass it manually. + # References: + # - https://github.com/SeleniumHQ/selenium/issues/16073 + # - https://github.com/SeleniumHQ/selenium/pull/16056 + edge_driver_url = "https://msedgedriver.microsoft.com" + installed_driver = manager( + url=edge_driver_url, + latest_release_url=f"{edge_driver_url}/LATEST_RELEASE", + cache_manager=cache_manager + ).install() + else: + installed_driver = manager(cache_manager=cache_manager).install() yield installed_driver # Issue: https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/551 diff --git a/tests/test_browser.py b/tests/test_browser.py index e65d218..e19be0c 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -34,6 +34,7 @@ def test_close_page(web: WebBot): def test_create_window(web: WebBot): web.browse(conftest.INDEX_PAGE) web.create_window(url=conftest.TEST_PAGE) + web.wait(3000) title = web.page_title() assert title == 'Page test' From 4bd95a9f099f70f2506d8dd39e3f7a4757744340 Mon Sep 17 00:00:00 2001 From: joao-voltarelli Date: Tue, 12 Aug 2025 12:31:38 -0300 Subject: [PATCH 2/4] TEST: Adjusting undetected_chrome setup --- conftest.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/conftest.py b/conftest.py index 2f3ccc3..c212491 100644 --- a/conftest.py +++ b/conftest.py @@ -45,8 +45,13 @@ def setup_undetected_chrome(headless: bool, tmp_folder: str, download_driver: st web = WebBot(headless) web.browser = Browser.UNDETECTED_CHROME + opt = browsers.undetected_chrome.default_options(headless=headless, download_folder_path=tmp_folder) + opt.add_argument("--disable-dev-shm-usage") + opt.add_argument("--disable-extensions") + web.driver_path = download_driver web.download_folder_path = tmp_folder + web.options = opt return web From 152d689f21779822972eec6fd2641d91d31d866a Mon Sep 17 00:00:00 2001 From: joao-voltarelli Date: Tue, 12 Aug 2025 13:18:44 -0300 Subject: [PATCH 3/4] ENH: Trying to ensure there is an active page before running the CDP command --- botcity/web/bot.py | 5 +++++ conftest.py | 5 ----- tests/test_browser.py | 2 ++ tests/test_vision.py | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/botcity/web/bot.py b/botcity/web/bot.py index f71cf76..8e057bc 100644 --- a/botcity/web/bot.py +++ b/botcity/web/bot.py @@ -356,6 +356,11 @@ def _others_configurations(self): https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/260#issuecomment-901276808. It will be a temporary solution. """ + try: + self.driver.get("about:blank") + except Exception: + pass + params = { "behavior": "allow", "downloadPath": self.download_folder_path diff --git a/conftest.py b/conftest.py index c212491..2f3ccc3 100644 --- a/conftest.py +++ b/conftest.py @@ -45,13 +45,8 @@ def setup_undetected_chrome(headless: bool, tmp_folder: str, download_driver: st web = WebBot(headless) web.browser = Browser.UNDETECTED_CHROME - opt = browsers.undetected_chrome.default_options(headless=headless, download_folder_path=tmp_folder) - opt.add_argument("--disable-dev-shm-usage") - opt.add_argument("--disable-extensions") - web.driver_path = download_driver web.download_folder_path = tmp_folder - web.options = opt return web diff --git a/tests/test_browser.py b/tests/test_browser.py index e19be0c..c615531 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -43,6 +43,7 @@ def test_create_window(web: WebBot): def test_display_size(web: WebBot): web.browse(conftest.INDEX_PAGE) web.set_screen_resolution(1280, 720) + web.wait(3000) (w, h) = web.display_size() assert w in [1280, 1233, 1223, 1028, 1264, 1176, 1256] @@ -242,6 +243,7 @@ def test_scroll_up(web: WebBot): def test_set_screen_resolution(web: WebBot): web.browse(conftest.INDEX_PAGE) web.set_screen_resolution(500, 500) + web.wait(3000) page_size = web.find_element('page-size', By.ID).text width = page_size.split('x')[0] diff --git a/tests/test_vision.py b/tests/test_vision.py index afefa5e..7f24758 100644 --- a/tests/test_vision.py +++ b/tests/test_vision.py @@ -48,6 +48,7 @@ def test_get_last_element(web: WebBot): def test_find_text(web: WebBot): web.browse(conftest.INDEX_PAGE) web.set_screen_resolution(3000, 2000) + web.wait(3000) web.add_image('hello_world', os.path.join(conftest.PROJECT_DIR, 'resources', 'hello_world.png')) ele = web.find("hello_world", matching=0.97, waiting_time=20000) From 4abc2ae725cb0f18f591f2269d1ec41ab2ff93b3 Mon Sep 17 00:00:00 2001 From: joao-voltarelli Date: Tue, 12 Aug 2025 13:47:02 -0300 Subject: [PATCH 4/4] ENH: Adjusting the treatment for the active page only for undetected_chrome --- botcity/web/bot.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/botcity/web/bot.py b/botcity/web/bot.py index 8e057bc..d970ec8 100644 --- a/botcity/web/bot.py +++ b/botcity/web/bot.py @@ -356,10 +356,11 @@ def _others_configurations(self): https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/260#issuecomment-901276808. It will be a temporary solution. """ - try: - self.driver.get("about:blank") - except Exception: - pass + if self.browser == Browser.UNDETECTED_CHROME: + try: + self.driver.get("about:blank") + except Exception: + pass params = { "behavior": "allow",