Use selenium webdriver as base python

I searched for a while for this and was surprised that I couldn’t find anything, maybe because it’s easy. I have been programming in python for about 3 months, doing automated testing with selenium webdriver. I thought it would be convenient to inherit a class from my webdriver class to add additional features to it.

    from selenium import webdriver

    class myPage(webdriver):

          def __init__(self):
                super(myPage, self).__init__()

          def set_up(self):
                #doStuff...

but when I do this, I get an error →>

    File "c:\Users\me\...\myProgram.py", line 6, in <module>
        class myPage(webdriver):
    TypeError: module.__init__() takes at most 2 arguments (3 given)

When I create myPage object, the code ...

    from myProgram import myPage
    class Test():
          def do(self):
                self.browser = myPage.Firefox()

So, it goes through and makes the line self.browser = myPage.Firefox (), and when it starts. __ init __ () somehow it gives three arguments, and I'm not sure where they come from. I am clearly missing something because inheritance is not complicated. Thanks for any help

+4
1

:

class myPage(webdriver)

To:

class myPage(webdriver.Firefox)

, . , webdriver , ( ). - : webdriver.Firefox(), Firefox, webdriver. , , , , - :

from selenium import webdriver

class myPage(webdriver.Firefox, webdriver.Chrome, webdriver.Ie):
    def __init__(self, browser):
        if browser.lower() == "ie":
            webdriver.Ie.__init__(self)
        elif browser.lower() == "chrome":
            webdriver.Chrome.__init__(self)
        else:
            webdriver.Firefox.__init__(self)
+6

Source: https://habr.com/ru/post/1542965/


All Articles