Exemplo n.º 1
0
    def get_search_context(self, element):
        driver = self.get_driver()
        if element is None:
            return driver
        from JDI.web.selenium.elements.composite.web_site import WebSite
        try:
            if isinstance(element, WebSite) or isinstance(element.get_parent(), WebSite):
                return driver
        except: pass
        try:
            if issubclass(element, WebSite) or issubclass(element.get_parent(), WebSite):
                return driver
        except: pass
        from JDI.web.selenium.elements.base.base_element import BaseElement
        from JDI.web.selenium.elements.base.element import Element
        if (element is None or type(element) is BaseElement) or \
                (element.get_parent() is None and element.avatar.frame_locator is None):
            return self.get_driver().switch_to.default_content()
        if type(element) is Element and element.avatar.has_web_element():
            return element.get_web_element
        locator = element.get_locator()
        search_context = self.get_driver().switch_to.default_content() \
            if WebDriverByUtils.contains_root(locator) \
            else self.get_search_context(element.get_parent())
        locator = WebDriverByUtils.trim_root(locator) \
            if WebDriverByUtils.contains_root(locator) \
            else locator

        frame = element.avatar.frame_locator
        if frame is not None:
            self.switch_to_last_opened_window()
            res = search_context.find_element(element.avatar.frame_locator[0], element.avatar.frame_locator[1])
            driver.switch_to_frame(res)
        return search_context.find_element(locator[0], locator[1]) if locator is not None else search_context
Exemplo n.º 2
0
    def __search_elements(self):
        search_context = self.get_driver() \
            if WebDriverByUtils.contains_root(self.by_locator) \
            else self.get_search_context(self.element.parent)

        locator = WebDriverByUtils.trim_root(self.by_locator) \
            if WebDriverByUtils.contains_root(self.by_locator) \
            else self.by_locator

        if search_context is None:
            search_context = self.get_driver()
        return search_context.find_elements(locator[0], locator[1])
Exemplo n.º 3
0
    def __search_elements(self):
        search_context = self.get_driver() \
            if WebDriverByUtils.contains_root(self.by_locator) \
            else self.get_search_context(self.element.parent)

        locator = WebDriverByUtils.trim_root(self.by_locator) \
            if WebDriverByUtils.contains_root(self.by_locator) \
            else self.by_locator

        if search_context is None:
            search_context = self.get_driver()
        return search_context.find_elements(locator[0], locator[1])
Exemplo n.º 4
0
 def get_element_by_template(self, value):
     locator = WebDriverByUtils.fill_by_template(
         self.by_line_template if self.by_line_template is not None else
         self.by_default_template, value)
     return list(
         filter(
             lambda el: el.is_displayed(),
             self.table.get_web_element().find_elements(
                 locator[0], locator[1])))
Exemplo n.º 5
0
    def get_search_context(self, element):
        driver = self.get_driver()
        if element is None:
            return driver
        from JDI.web.selenium.elements.composite.web_site import WebSite
        try:
            if isinstance(element, WebSite) or isinstance(
                    element.get_parent(), WebSite):
                return driver
        except:
            pass
        try:
            if issubclass(element, WebSite) or issubclass(
                    element.get_parent(), WebSite):
                return driver
        except:
            pass
        from JDI.web.selenium.elements.base.base_element import BaseElement
        from JDI.web.selenium.elements.base.element import Element
        if (element is None or type(element) is BaseElement) or \
                (element.get_parent() is None and element.avatar.frame_locator is None):
            return self.get_driver().switch_to.default_content()
        if type(element) is Element and element.avatar.has_web_element():
            return element.get_web_element
        locator = element.get_locator()
        search_context = self.get_driver().switch_to.default_content() \
            if WebDriverByUtils.contains_root(locator) \
            else self.get_search_context(element.get_parent())
        locator = WebDriverByUtils.trim_root(locator) \
            if WebDriverByUtils.contains_root(locator) \
            else locator

        frame = element.avatar.frame_locator
        if frame is not None:
            self.switch_to_last_opened_window()
            res = search_context.find_element(element.avatar.frame_locator[0],
                                              element.avatar.frame_locator[1])
            driver.switch_to_frame(res)
        return search_context.find_element(
            locator[0], locator[1]) if locator is not None else search_context
Exemplo n.º 6
0
 def get_element_by_template(self, value):
     locator = WebDriverByUtils.fill_by_template(
         self.by_line_template if self.by_line_template is not None else self.by_default_template, value)
     return list(filter(lambda el: el.is_displayed(), self.table.get_web_element().find_elements(locator[0], locator[1])))
Exemplo n.º 7
0
 def get(self):
     cell = SelectElement(web_element=self.web_element) if self.web_element is not None else \
         SelectElement(
             WebDriverByUtils.fill_by_template(self.cell_locator_template, [self.column_index, self.row_index]))
     cell.init(parent=self.table, avatar=cell.avatar)
     return cell