Injecting custom webdriver to seleniumbase - is it possible? #812
-
Hey 👋 I am using seleniumbase currently and was wondering if it is possible to inject customized version of selenium webdriver instead of default one. Simple example - like using the one from https://github.com/wkeeling/selenium-wire instead. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 11 replies
-
Hello @rafalpomocnik-payability , yes it's possible. See this example: from seleniumbase import BaseCase
from seleniumwire import webdriver
class MyTestClass(BaseCase):
def test_wire(self):
driver2 = webdriver.Firefox()
self._drivers_list.append(driver2)
self.driver = driver2
self.open("https://www.google.com")
self.type('input[title="Search"]', 'SeleniumBase\n')
for request in self.driver.requests:
if request.response:
print(
request.url,
request.response.status_code,
request.response.headers['Content-Type']
) That test spins up a second web browser using selenium-wire, and then that test has access to seleniumbase methods. When |
Beta Was this translation helpful? Give feedback.
-
Here's a generic answer for using a custom WebDriver while still having access to all seleniumbase methods. Keep in mind that if using this technique, most command-line options will have no effect because this overrides the default from seleniumbase import BaseCase
from selenium import webdriver
class BaseTestCase(BaseCase):
def get_new_driver(self, *args, **kwargs):
self.driver = webdriver.Firefox()
self._drivers_list = [self.driver]
return self.driver
def setUp(self):
super(BaseTestCase, self).setUp()
def test_custom_webdriver(self):
self.open("https://www.google.com")
self.type('input[title="Search"]', 'SeleniumBase\n') |
Beta Was this translation helpful? Give feedback.
-
Hi! I have been really enjoying the library, thank you for all the hard work. How would you in addition to using a custom driver also turn on uc mode ie uc=True. Would that be in the setup method ? |
Beta Was this translation helpful? Give feedback.
Here's a generic answer for using a custom WebDriver while still having access to all seleniumbase methods. Keep in mind that if using this technique, most command-line options will have no effect because this overrides the default
get_new_driver()
method, which uses the options for configuring the WebDriver browser.