Selenium - can WebDriverWait (). before (myFunc) to use functions outside of WebDriver?

Is it possible to call a function outside of WebDriver in .until? No matter what I try, I get the exception:

Exception: 'WebDriver' object has no attribute 'verifyObj_tag'. 

      

I have a class called "ad_selenium" and all calls to selenium are encapsulated in a library. The explicit function explicitWait I wrote tries to use a different class method in .until:

def explicitWait(self,tag_name,search_for,element=None,compare='contains',seconds=20):
    element = WebDriverWait(self.__WD, seconds).until( lambda self: \
        self.verifyObj_tag(tag_name,search_for,element=element,compare=compare))

      

I've tried all sorts of combinations of lambda functions and functions:

def explicitWait(self,tag_name,search_for,element=None,compare='contains',seconds=20):
    x = self.verifyObj_tag
    element = WebDriverWait(self.__WD, seconds).until( lambda x: \
        x(tag_name,search_for,element=element,compare=compare))

      

Looking at the code inside selenium / webdriver / support / wait.py it looks like it always passes the webriver to the method passed as long as:

def until(self, method, message=''):
    while(True):
        try:
            value = method(self._driver)   #<<--webdriver passed here
            if value:
                return value
        except self._ignored_exceptions:
            pass

      

Any ideas on how to make this work?

+3


source to share


1 answer


You need to allow it to be passed driver

as an argument:



element = WebDriverWait(self.__WD, seconds).until(lambda driver: \
    self.verifyObj_tag(tag_name, search_for, element=element, compare=compare))

      

+2


source







All Articles