def _validate_params(self):
     if self.by and not self.value:
         raise WebiumException('Provide search value in addition to by')
     if not self.by:
         if issubclass(self.ui_type, WebElement):
             raise WebiumException('Logical containers shouldn\'t be WebElement')
     else:
         if not issubclass(self.ui_type, WebElement):
             raise WebiumException('UI types should inherit WebElement')
Exemple #2
0
 def is_displayed():
     element = getattr(self, element_name, None)
     if not element:
         raise WebiumException(
             'No element "{0}" within container {1}'.format(
                 element_name, self))
     return element.is_displayed()
Exemple #3
0
 def is_displayed():
     try:
         element = getattr(self, element_name)
     except AttributeError:
         raise WebiumException('No element "{0}" within container {1}'.format(element_name, self))
     if isinstance(element, list):
         if element:
             return all(ele.is_displayed() for ele in element)
         else:
             return False
     return element.is_displayed()
Exemple #4
0
    def _search_element(self):
        found = False
        startTime = time()
        originalTimeout = webium.settings.implicit_timeout
        webium.settings.implicit_timeout = 0
        notTimeout = True
        while notTimeout:
            for selector in self.selectors:
                self.by = selector[0]
                self.value = selector[1]
                try:

                    if not self.context:
                        raise WebiumException(
                            "Search context should be defined with dynamic Find usage."
                            + " Please define context in __init__.")
                    if (self.by is not None) and (self.value is not None):
                        web_element = self.context.find_element(
                            self.by, self.value)
                        web_element.__class__ = self.ui_type
                        self._target_element = web_element
                        found = True
                    else:
                        container = self.ui_type()
                        container.find_element = self.context.find_element
                        container.find_elements = self.context.find_elements
                        self._target_element = container
                        found = True
                    self._target_element.is_element_present = MethodType(
                        is_element_present, self._target_element)
                    self._target_element.implicitly_wait = self.context.implicitly_wait
                    if len(self.init_args) or len(self.init_kwargs) > 0:
                        self._target_element.__init__(*self.init_args,
                                                      **self.init_kwargs)
                    webium.settings.implicit_timeout = originalTimeout
                    return
                except NoSuchElementException:
                    pass
                except WebDriverException:
                    pass
                except:
                    raise

            if time() - startTime > originalTimeout:
                notTimeout = False
            raise NoSuchElementException(
                msg='Could not find element with identifiers [%s]' %
                self.selectors)
 def _search_element(self):
     if not self.context:
         raise WebiumException("Search context should be defined with dynamic Find usage." +
                               " Please define context in __init__.")
     if (self.by is not None) and (self.value is not None):
         web_element = self.context.find_element(self.by, self.value)
         web_element.__class__ = self.ui_type
         self._target_element = web_element
     else:
         container = self.ui_type()
         container.find_element = self.context.find_element
         container.find_elements = self.context.find_elements
         self._target_element = container
     self._target_element.is_element_present = MethodType(is_element_present, self._target_element)
     if len(self.init_args) or len(self.init_kwargs) > 0:
         self._target_element.__init__(*self.init_args, **self.init_kwargs)
Exemple #6
0
 def open(self):
     if not self.url:
         raise WebiumException('Can\'t open page without url')
     self._driver.get(self.url)
 def _validate_params(self):
     if not self.value:
         raise WebiumException('Provide value to search elements')
     if not issubclass(self.ui_type, WebElement):
         raise WebiumException('Finds is applicable only for WebElements')
Exemple #8
0
 def open_home_page(self):
     if not self.url:
         raise WebiumException('Can\'t open page without url')
     self.__driver.get(self.url)
     logger.info('open home page')
Exemple #9
0
 def open_with_params(self, params):
     if not self.url:
         raise WebiumException('Can\'t open page without url')
     url = Template(self.url).safe_substitute(params)
     self._driver.get(url)
Exemple #10
0
 def _validate_params(self):
     if not issubclass(self.ui_type, WebElement):
         raise WebiumException('UI types should inherit WebElement')