1

I am trying to call get_driver_path inside __new__ method, and I get this error when I try to run the full code:

TypeError: unbound method get_chrome_driver() must be called with
WebBrowserManager instance as first argument (got str instance instead

Here is the code:

def __new__(self, driver = 'firefox'):
    if not self._instance:
        self._instance = super(WebBrowserManager, self).__new__(self)
        self._profile.native_events_enabled = True
        self.data = {}
        self._system = platform.system()
        if self._local:
            if driver == 'firefox':
                self.browser = webdriver.Firefox(self._profile)
            elif driver == 'chrome':
                self.browser = self.get_chrome_driver(self._system, driver)
            elif driver == 'ie':
                assert self._system == 'Windows', 'Tests on Internet Explorer are only supported on Windows'
                self.browser = webdriver.Ie(self.get_driver_path(driver))
    return self._instance

def get_driver_path(self, driver):
    driver_name = ''
    if driver == 'ie':
        driver_name = 'IEDriverServer.exe'
    elif driver == 'chrome':
       driver_name = 'chromedriver.exe'
    driver_path = "selenium_drivers\\" + driver_name 
    os.environ["webdriver." + driver + ".driver"] = driver_path
    return driver_path

1 Answer 1

2

Since you made it an instance method, you would need to call it on the instance you created in the __new__ method (which is static; e.g. not bound to an instance or a class):

self.browser = webdriver.Ie(self._instance.get_driver_path(driver))

You could make that method static or a class method instead, at which point you can use it via the first argument to __new__ (which is the class, not an instance; usually you don't use the name self but cls instead):

@staticmethod
def get_driver_path(driver):

Note that a staticmethod then doesn't take a self argument, but your get_driver_path() implementation doesn't use that anyway.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.