Exemplo n.º 1
0
def findElementBy(self: (WebElement, webdriver), by=By.ID, value=None):
    try:
        return self.find_element(by, value)
        # return WebDriverWait(self, 1).until(EC.presence_of_element_located((By.ID, "Passwd")))
    except NoSuchElementException:
        return WebElement(self, id(self))
    except StaleElementReferenceException:
        return WebElement(self, id(self))
    except WebDriverException:
        return WebElement(self, id(self))
Exemplo n.º 2
0
def findElementBy(self: (WebElement, webdriver), by=By.ID, value=None):
    try:
        # return self.find_element(by,value)
        return WebDriverWait(Globals.Test.Browser, 10).until(
            EC.presence_of_element_located((by, value)))
    except NoSuchElementException:
        return WebElement(self, id(self))
    except StaleElementReferenceException:
        return WebElement(self, id(self))
    except WebDriverException:
        return WebElement(self, id(self))
Exemplo n.º 3
0
def findElementsBy(self: (WebElement, webdriver), by=By.ID, value=None):
    try:
        return self.find_elements(by, value)
    except NoSuchElementException:
        return WebElement(self, id(self))
    except TimeoutException:
        return WebElement(self, id(self))
    except StaleElementReferenceException:
        return WebElement(self, id(self))
    except WebDriverException:
        return WebElement(self, id(self))
Exemplo n.º 4
0
 def _get_box(self):
     """Caching of the opened box"""
     if getattr(self, "_box_id", None) is None:
         self._open_box()
         for box in sel.elements(self._box):
             try:
                 sel.move_to_element(box)
                 if sel.is_displayed(box):
                     self._box_id = box.id
                     return box
             except sel.NoSuchElementException:
                 pass
         else:
             raise Exception("Could not open the box!")
     else:
         el = WebElement(sel.browser(), self._box_id)
         try:
             el.tag_name
             if not sel.is_displayed(el):
                 raise NotDisplayedException()
             return el
         except (StaleElementReferenceException, NoSuchElementException,
                 NotDisplayedException):
             del self._box_id
             return self._get_box()
Exemplo n.º 5
0
    def find_elements_by_locator(self, locator):
        locator_type = locator[:locator.find("=")]
        if locator_type == "":
            raise saunter.exceptions.InvalidLocatorString(locator)
        locator_value = locator[locator.find("=") + 1:]
        if locator_type == 'class':
            elements = self.find_elements_by_class_name(locator_value)
        elif locator_type == 'css':
            elements = self.find_elements_by_css_selector(locator_value)
        elif locator_type == 'id':
            elements = self.find_elements_by_id(locator_value)
        elif locator_type == 'link':
            elements = self.find_elements_by_link_text(locator_value)
        elif locator_type == 'name':
            elements = self.find_elements_by_name(locator_value)
        elif locator_type == 'plink':
            elements = self.find_elements_by_partial_link_text(locator_value)
        elif locator_type == 'tag':
            elements = self.find_elements_by_tag_name(locator_value)
        elif locator_type == 'xpath':
            elements = self.find_elements_by_xpath(locator_value)
        else:
            raise saunter.exceptions.InvalidLocatorString(locator)

        return [WebElement(e) for e in elements]
Exemplo n.º 6
0
 def run_script(self, script: str, *args) -> Any:
     """执行js代码,传入自己为第一个参数  \n
     :param script: js文本
     :param args: 传入的参数
     :return: js执行结果
     """
     shadow_root = WebElement(self.page.driver, self.inner_ele._id)
     return shadow_root.parent.execute_script(script, shadow_root, *args)
Exemplo n.º 7
0
 def test_should_be_loaded_with_elements_present(self):
     web_element = WebElement(None, None)
     view = AllRequiredView()
     driver = Driver()
     driver.find_element = MagicMock(return_value=web_element)
     view.__set_driver__(driver)
     self.assertTrue(view.is_loaded())
     driver.close()
Exemplo n.º 8
0
 def _wrap_elements(self, elements):
     for element in elements:
         element._target_element = WebElement(element.parent, element.id,
                                              element._w3c)
         element.__class__ = self.wrapper_class
         element.by = self.by
         element.value = self.value
         element.driver = self.driver
Exemplo n.º 9
0
 def setUp(self):
     """Instantiate the extended element class."""
     self.element = ExtendedElementKeywords()
     self.element._current_browser = mock.Mock()
     self.element._wait_until_page_ready = mock.Mock()
     self.locator = 'css=.selector'
     self.locator_attribute = 'css=.selector@class'
     self.locator_class = 'selector'
     self.web_element = WebElement('element', False)
Exemplo n.º 10
0
 def test_component_can_be_created_from_web_element(self):
     component = UIComponent(self.driver, 'a component', [By.ID, 'theId'])
     a_web_element = WebElement(None, '')
     ##
     component.from_web_element(a_web_element)
     ##
     assert_that(
         component.locate(), equal_to(a_web_element),
         "fromWebElement should store a reference to passed WebElement")
Exemplo n.º 11
0
 def mouseHoverUsingXpath(self, xpath):
     """
     Calls mouse hover using actions
     :param element - Web Element
     """
     element = self.driver.find_elements_by_xpath(xpath=xpath)
     actionChains = ActionChains(self.driver)
     actionChains.move_to_element(WebElement(element))
     actionChains.perform()
Exemplo n.º 12
0
 def setUp(self):
     """Instantiate the extended form element class."""
     self.driver = mock.Mock()
     self.driver.session_id = 'session'
     self.element = ExtendedFormElementKeywords()
     # pylint: disable=protected-access
     self.element._info = mock.Mock()
     self.element._wait_until_page_ready = mock.Mock()
     self.group_name = 'group'
     self.locator = 'css=.selector'
     self.value = 'value'
     self.web_element = WebElement(self.driver, 'element', False)
     self.web_element.click = mock.Mock()
Exemplo n.º 13
0
 def setUp(self):
     """Instantiate the extended element class."""
     self.driver = mock.Mock()
     self.driver.session_id = 'session'
     self.element = ExtendedElementKeywords()
     # pylint: disable=protected-access
     self.element._current_browser = mock.Mock()
     self.element._info = mock.Mock()
     self.element._wait_until_page_ready = mock.Mock()
     self.locator = 'css=.selector'
     self.locator_attribute = 'css=.selector@class'
     self.locator_class = 'selector'
     self.web_element = WebElement(self.driver, 'element', False)
     self.web_element.click = mock.Mock()
Exemplo n.º 14
0
 def perform_action(driver, action):
     try:
         if action.id == 'noop':
             pass
         elif action.id == 'click':
             id = action.args[0]
             element = WebElement(driver, id)
             ActionChains(driver).move_to_element(element).click(
                 element).perform()
         elif action.id == 'doubleClick':
             id = action.args[0]
             element = WebElement(driver, id)
             ActionChains(driver).move_to_element(
                 element).double_click(element).perform()
         elif action.id == 'focus':
             id = action.args[0]
             element = WebElement(driver, id)
             element.send_keys("")
         elif action.id == 'keyPress':
             char = action.args[0]
             element = driver.switch_to.active_element
             element.send_keys(char)
         elif action.id == 'enterText':
             element = driver.switch_to.active_element
             element.send_keys(action.args[0])
         elif action.id == 'enterTextInto':
             id = action.args[1]
             element = WebElement(driver, id)
             element.send_keys(action.args[0])
         elif action.id == 'clear':
             id = action.args[0]
             element = WebElement(driver, id)
             element.clear()
         else:
             raise UnsupportedActionError(action)
     except Exception as e:
         raise PerformActionError(action, e)
Exemplo n.º 15
0
    def test_method(self):
        self.driver.find_element_by_id('kw').send_keys('极客时间')
        self.driver.find_element_by_id('su').click()
        sleep(2)
        self.driver.back()
        sleep(2)
        self.driver.refresh()
        sleep(2)
        self.driver.forward()
        sleep(2)

        self.driver.close()
        sleep(2)

        self.driver.quit()

        wb = WebElement()
 def setUp(self):
     """Instantiate the extended element finder class."""
     self.default_strategies = ['binding', 'button', 'css', 'default', 'dom',
                                'id', 'identifier', 'jquery', 'link', 'model',
                                'name', 'options', 'partial binding',
                                'partial button', 'partial link', 'scLocator',
                                'sizzle', 'tag', 'xpath']
     self.driver = mock.Mock()
     self.driver.session_id = 'session'
     self.finder = ExtendedElementFinder()
     self.finder._filter_elements = mock.Mock()
     self.finder._find_by_css_selector = mock.Mock()
     self.finder.BUTTON_TEXT_WRAPPER = 'return buttons;%(handler)s'
     self.finder.NG_BINDING_WRAPPER = 'return bindings;%(handler)s'
     self.ng_prefixes = ['ng-', 'data-ng-', 'ng_', 'x-ng-', 'ng\\:']
     self.web_element = WebElement(self.driver, 'element', False)
     self.finder._filter_elements.return_value = self.web_element
     self.finder._find_by_css_selector.return_value = self.web_element
Exemplo n.º 17
0
def _find_by_css_selector(root, css_selector, raise_exception):
    element = None
    try:
        # Chrome 96+ returns the element as a dict that includes the id
        if isinstance(root, dict):
            key = list(root.keys())[0]
            shadow_root_el = WebElement(_get_driver(), root[key])
            element = shadow_root_el.find_element_by_css_selector(css_selector)
        else:
            element = root.find_element_by_css_selector(css_selector)
    except NoSuchElementException as nse:
        if raise_exception:
            if root.tag_name == "slot":
                raise TaurusException(
                    "Shadow DOM Slots are currently not supported in Taurus execution."
                )
            raise nse
        pass
    return element
Exemplo n.º 18
0
    def test_QueryResult_methods(self):
        mock = Mock()
        mock.reason_storage = {'last css query': ''}
        mock.config.POLLING_DELAY = 1.0
        mock.config.POLLING_TIMEOUT = 10.0
        mock.disable_polling = WebElementProxy(WebElement('1',
                                                          1)).disable_polling

        query = QueryResult(mock, 'css')
        self.assertIsNotNone(query.__we)
        self.assertIsNotNone(query.__css)
        self.assertIsNotNone(query.__proxy)

        res = query.__repr__()
        self.assertIsNotNone(res)

        res = query.__css_string__()
        self.assertNotEqual(res, query.__css)

        res = query.wait()
        self.assertNotEqual(res, mock)
def find_element_by_locator(driver, locator):
    locator_type, locator_value = locator.split('=', 1)
    if locator_type == 'id':
        if locator_type == 'class':
            return WebElement(driver.find_element_by_class_name(locator_value))
        elif locator_type == 'css':
            return WebElement(
                driver.find_element_by_css_selector(locator_value))
        elif locator_type == 'id':
            return WebElement(driver.find_element_by_id(locator_value))
        elif locator_type == 'link':
            return WebElement(driver.find_element_by_link_text(locator_value))
        elif locator_type == 'name':
            return WebElement(driver.find_element_by_name(locator_value))
        elif locator_type == 'link':
            return WebElement(
                driver.find_element_by_partial_link_text(locator_value))
        elif locator_type == 'tag':
            return WebElement(driver.find_element_by_tag_name(locator_value))
        elif locator_type == 'xpath':
            return WebElement(driver.find_element_by_xpath(locator_value))
        else:
            raise Exception('Invalid locator')
Exemplo n.º 20
0
 def test_hash(self):
     mock_id = str(randint(1, 999999999))
     self.mock_element.id = mock_id
     other_element = WebElement(None, mock_id)
     self.assertEqual(hash(self.element_wrapper), hash(other_element))
Exemplo n.º 21
0
def test_get_web_element_from_web_element(utils):
    element = WebElement(None, 1)
    web_element = utils.get_web_element(element)
    assert element == web_element
Exemplo n.º 22
0
 def test_get_web_element_from_web_element(self):
     element = WebElement(None, 1)
     web_element = self.utils.get_web_element(element)
     assert_equal(element, web_element)
Exemplo n.º 23
0
 def test_should_allow_mixin(self):
     button = Button(By.ID, 'foo')
     button.web_element = WebElement(None, None)
     button.web_element.is_enabled = MagicMock(return_value=True)
     self.assertTrue(button.is_enabled())
Exemplo n.º 24
0
 def create_web_element(self, element_id):
     """Override from RemoteWebDriver to use firefox.WebElement."""
     return WebElement(self, element_id)
Exemplo n.º 25
0
 def inner_html(self) -> str:
     """返回内部的html文本"""
     shadow_root = WebElement(self.page.driver, self.inner_ele._id)
     return shadow_root.get_attribute('innerHTML')
Exemplo n.º 26
0
def poc():
    try:
        ele = WebElement()
    except:
        pass
    raise Exception("if printed, you can't reproduce this behaviour")
Exemplo n.º 27
0
 def test_QueryObject_call_method(self):
     query = QueryObject('la', el={"la": 123})
     proxy = WebElementProxy(WebElement('1', 1))
     query.__call__(proxy)
     self.assertIsInstance(query, QueryObject)
Exemplo n.º 28
0
 def changetoWebElement(self):
     return WebElement(self.parent,self.id,self.w3c)
Exemplo n.º 29
0
 def test_window_id_is_web_element(self):
     driver = MockWebDriver()
     elem = WebElement(None, '052b083c-0d6e-45ca-bda6-73ca13c42561')
     when(driver).execute_script(SCRIPT).thenReturn([elem, '', '', ''])
     info = driver.get_current_window_info()
     self.assertEqual(info[1], elem)