-
Notifications
You must be signed in to change notification settings - Fork 1.4k
-
I have a code block which uses a Seleniumbase webdriver:
from seleniumbase import BaseCase
BaseCase.main(__name__, __file__, "--uc")
class MultipleDriversTest(BaseCase):
def test_multiple_drivers(self):
if self.browser == "safari":
self.open_if_not_url("about:blank")
print("\n Safari doesn't support multiple drivers.")
self.skip("Safari doesn't support multiple drivers.")
url1 = "https://invideo.io/perf/ga-ai-video-generator-web/?utm_source=google&utm_medium=cpc&utm_campaign=Top16_Search_Brand_Exact_EN&adset_name=InVideo&keyword=invideo&network=g&device=c&utm_term=invideo&utm_content=InVideo&matchtype=e&placement=g&campaign_id=18035330768&adset_id=140632017072&ad_id=616240030555&gad_source=1&gclid=Cj0KCQiAvvO7BhC-ARIsAGFyToWFf0L_8iqkB32qg9prKxVApsklZ8HA69LW2O0Z6XC1nbXXz9sCTTEaAinZEALw_wcB"
self.activate_cdp_mode(url1)
url2 = "https://temp-mail.org/en"
driver2 = self.get_new_driver(undetectable=True)
driver2.uc_activate_cdp_mode(url2)
self.sleep(2)
self.switch_to_default_driver()
self.sleep(2)
self.switch_to_driver(driver2)
When I run this code, I receive the following error:
self = <test16.MultipleDriversTest testMethod=test_multiple_drivers>
def bring_active_window_to_front(self):
"""Brings the active browser window to the front (on top).
Useful when multiple drivers are being used at the same time."""
self.__check_scope()
if self.__is_cdp_swap_needed():
> self.cdp.bring_active_window_to_front()
E AttributeError: 'NoneType' object has no attribute 'bring_active_window_to_front'
AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\seleniumbase\fixtures\base_case.py:5791: AttributeError
------------------------------------ Latest Logs dir: C:\Users\zvirg\latest_logs\ -------------------------------------
=============================================== short test summary info ===============================================
FAILED Programs/test16.py::MultipleDriversTest::test_multiple_drivers - AttributeError: 'NoneType' object has no attribute 'bring_active_window_to_front'
What could be the reason for this error?
Beta Was this translation helpful? Give feedback.
All reactions
When activating UC Mode from multiple drivers, try it like this:
from seleniumbase import BaseCase BaseCase.main(__name__, __file__, "--uc") class MultipleDriversTest(BaseCase): def test_multiple_drivers(self): url1 = "https://seleniumbase.io/demo_page" self.activate_cdp_mode(url1) url2 = "https://seleniumbase.io/coffee/" driver2 = self.get_new_driver(undetectable=True) self.activate_cdp_mode(url2) self.sleep(2) self.switch_to_default_driver() print(self.get_current_url()) self.sleep(2) self.switch_to_driver(driver2) print(self.get_current_url())
Replies: 1 comment 4 replies
-
When activating UC Mode from multiple drivers, try it like this:
from seleniumbase import BaseCase BaseCase.main(__name__, __file__, "--uc") class MultipleDriversTest(BaseCase): def test_multiple_drivers(self): url1 = "https://seleniumbase.io/demo_page" self.activate_cdp_mode(url1) url2 = "https://seleniumbase.io/coffee/" driver2 = self.get_new_driver(undetectable=True) self.activate_cdp_mode(url2) self.sleep(2) self.switch_to_default_driver() print(self.get_current_url()) self.sleep(2) self.switch_to_driver(driver2) print(self.get_current_url())
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks, I have tried this code and it was successful, however the output appears to display url2
twice. I assume it should display url1
then url2
?
Beta Was this translation helpful? Give feedback.
All reactions
-
Valid point. Try this code instead:
from seleniumbase import BaseCase BaseCase.main(__name__, __file__, "--uc") class MultipleDriversTest(BaseCase): def test_multiple_drivers(self): url1 = "https://seleniumbase.io/demo_page" driver1 = self.driver self.activate_cdp_mode(url1) url2 = "https://seleniumbase.io/coffee/" driver2 = self.get_new_driver(undetectable=True) self.activate_cdp_mode(url2) self.sleep(2) print(driver1.get_current_url()) self.sleep(2) print(driver2.get_current_url())
Beta Was this translation helpful? Give feedback.
All reactions
-
I'll need to ship a fix for switch_to_default_driver()
and switch_to_driver(driver)
when CDP Mode is being used, as the active CDP Driver wasn't swapped with those methods.
Beta Was this translation helpful? Give feedback.
All reactions
-
Valid point. Try this code instead:
from seleniumbase import BaseCase BaseCase.main(__name__, __file__, "--uc") class MultipleDriversTest(BaseCase): def test_multiple_drivers(self): url1 = "https://seleniumbase.io/demo_page" driver1 = self.driver self.activate_cdp_mode(url1) url2 = "https://seleniumbase.io/coffee/" driver2 = self.get_new_driver(undetectable=True) self.activate_cdp_mode(url2) self.sleep(2) print(driver1.get_current_url()) self.sleep(2) print(driver2.get_current_url())
Thanks, this worked perfectly.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1