Combine Selenium-Wire and Selenium-Requests

Viewed 827

i trying to figure out how i can handle Selenium-Wire and Requests.

from seleniumrequests.request import RequestMixin
from seleniumwire import webdriver


class MyCustomWebDriver(RequestMixin, webdriver):
    pass


custom_webdriver = MyCustomWebDriver()
response = custom_webdriver.request('GET', 'https://www.google.com/')
print(response)

This getting me the Error

TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

Can someone help me out with this?

Thanx in advanced.

2 Answers

As noted by C. Peck, webdriver is a module, not a class. You need to import a specific webdriver class, like so:

from seleniumrequests.request import RequestsSessionMixin
from seleniumwire.webdriver import Chrome

class MyCustomWebDriver(Chrome,RequestsSessionMixin):
    pass

custom_webdriver = MyCustomWebDriver()
response = custom_webdriver.request('GET', 'https://www.google.com/')
print(response)

I'm in no way a python expert, but theoretically couldn't you create a class, and super().init() both of those class properties?

I imagine this would be process intensive and may have overlapping conflicts if you attempted to combine them without breaking functionality of shared class properties.

Related