当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.StaleElementReferenceException方法代码示例

本文整理汇总了Python中selenium.common.exceptions.StaleElementReferenceException方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.StaleElementReferenceException方法的具体用法?Python exceptions.StaleElementReferenceException怎么用?Python exceptions.StaleElementReferenceException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在selenium.common.exceptions的用法示例。


在下文中一共展示了exceptions.StaleElementReferenceException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _expected_condition_find_element_containing_text

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import StaleElementReferenceException [as 别名]
def _expected_condition_find_element_containing_text(self, element_text_pair):
        """Tries to find the element and checks that it contains the specified text, but does not thrown an exception if the element is
            not found

        :param element_text_pair: Tuple with 2 items where:
            [0] element: PageElement or element locator as a tuple (locator_type, locator_value) to be found
            [1] text: text to be contained into the element
        :returns: the web element if it contains the text or False
        :rtype: selenium.webdriver.remote.webelement.WebElement or appium.webdriver.webelement.WebElement
        """
        element, text = element_text_pair
        web_element = self._expected_condition_find_element(element)
        try:
            return web_element if web_element and text in web_element.text else False
        except StaleElementReferenceException:
            return False 
开发者ID:Telefonica,项目名称:toolium,代码行数:18,代码来源:driver_utils.py

示例2: _expected_condition_find_element_not_containing_text

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import StaleElementReferenceException [as 别名]
def _expected_condition_find_element_not_containing_text(self, element_text_pair):
        """Tries to find the element and checks that it does not contain the specified text,
            but does not thrown an exception if the element is found

        :param element_text_pair: Tuple with 2 items where:
            [0] element: PageElement or element locator as a tuple (locator_type, locator_value) to be found
            [1] text: text to not be contained into the element
        :returns: the web element if it does not contain the text or False
        :rtype: selenium.webdriver.remote.webelement.WebElement or appium.webdriver.webelement.WebElement
        """
        element, text = element_text_pair
        web_element = self._expected_condition_find_element(element)
        try:
            return web_element if web_element and text not in web_element.text else False
        except StaleElementReferenceException:
            return False 
开发者ID:Telefonica,项目名称:toolium,代码行数:18,代码来源:driver_utils.py

示例3: _expected_condition_value_in_element_attribute

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import StaleElementReferenceException [as 别名]
def _expected_condition_value_in_element_attribute(self, element_attribute_value):
        """Tries to find the element and checks that it contains the requested attribute with the expected value,
           but does not thrown an exception if the element is not found

        :param element_attribute_value: Tuple with 3 items where:
            [0] element: PageElement or element locator as a tuple (locator_type, locator_value) to be found
            [1] attribute: element's attribute where to check its value
            [2] value: expected value for the element's attribute
        :returns: the web element if it contains the expected value for the requested attribute or False
        :rtype: selenium.webdriver.remote.webelement.WebElement or appium.webdriver.webelement.WebElement
        """
        element, attribute, value = element_attribute_value
        web_element = self._expected_condition_find_element(element)
        try:
            return web_element if web_element and web_element.get_attribute(attribute) == value else False
        except StaleElementReferenceException:
            return False 
开发者ID:Telefonica,项目名称:toolium,代码行数:19,代码来源:driver_utils.py

示例4: refresh_element

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import StaleElementReferenceException [as 别名]
def refresh_element(self, elem, timeout=10):
        """
        selenium API
        Refreshes the current page, retrieve elements.
        """
        warnings.warn("use driver.elem.refresh_element() instead",
                      DeprecationWarning, stacklevel=2)
        try:
            timeout_int = int(timeout)
        except TypeError:
            raise ValueError("Type 'timeout' error, must be type int() ")

        for i in range(timeout_int):
            if elem is not None:
                try:
                    elem
                except StaleElementReferenceException:
                    self.driver.refresh()
                else:
                    break
            else:
                sleep(1)
        else:
            raise TimeoutError("stale element reference: element is not attached to the page document.") 
开发者ID:SeldomQA,项目名称:poium,代码行数:26,代码来源:webdriver.py

示例5: refresh_element

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import StaleElementReferenceException [as 别名]
def refresh_element(self, timeout=10):
        """
        selenium API
        Refreshes the current page, retrieve elements.
        """
        try:
            timeout_int = int(timeout)
        except TypeError:
            raise ValueError("Type 'timeout' error, must be type int() ")

        elem = self.__get_element(self.k, self.v)
        for i in range(timeout_int):
            if elem is not None:
                try:
                    elem
                except StaleElementReferenceException:
                    Browser.driver.refresh()
                else:
                    break
            else:
                sleep(1)
        else:
            raise TimeoutError("stale element reference: element is not attached to the page document.") 
开发者ID:SeldomQA,项目名称:poium,代码行数:25,代码来源:page_objects.py

示例6: get_element_text

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import StaleElementReferenceException [as 别名]
def get_element_text(self, element):
        """
        [Internal]

        Gets element text.

        :param element: Selenium element
        :type element: Selenium object

        :return: Element text
        :rtype: str

        Usage:

        >>> #Defining the element:
        >>> element = lambda: self.driver.find_element_by_id("example_id")
        >>> #Calling the method
        >>> text = self.get_element_text(element())
        """
        try:
            return self.driver.execute_script("return arguments[0].innerText", element)
        except StaleElementReferenceException:
            print("********Element Stale get_element_text*********")
            pass 
开发者ID:totvs,项目名称:tir,代码行数:26,代码来源:base.py

示例7: get_element_value

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import StaleElementReferenceException [as 别名]
def get_element_value(self, element):
        """
        [Internal]

        Gets element value.

        :param element: Selenium element
        :type element: Selenium object

        :return: Element value
        :rtype: str

        Usage:

        >>> #Defining the element:
        >>> element = lambda: self.driver.find_element_by_id("example_id")
        >>> #Calling the method
        >>> text = self.get_element_value(element())
        """
        try:
            return self.driver.execute_script("return arguments[0].value", element)
        except StaleElementReferenceException:
            print("********Element Stale get_element_value*********")
            pass 
开发者ID:totvs,项目名称:tir,代码行数:26,代码来源:base.py

示例8: scroll_to_element

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import StaleElementReferenceException [as 别名]
def scroll_to_element(self, element):
        """
        [Internal]

        Scroll to element on the screen.

        :param element: Selenium element
        :type element: Selenium object

        Usage:

        >>> #Defining an element:
        >>> element = lambda: self.driver.find_element_by_id("example_id")
        >>> #Calling the method
        >>> self.scroll_to_element(element())
        """
        try:
            if element.get_attribute("id"):
                self.driver.execute_script("return document.getElementById('{}').scrollIntoView();".format(element.get_attribute("id")))
            else:
                self.driver.execute_script("return arguments[0].scrollIntoView();", element)
        except StaleElementReferenceException:
            print("********Element Stale scroll_to_element*********")
            pass 
开发者ID:totvs,项目名称:tir,代码行数:26,代码来源:base.py

示例9: set_element_focus

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import StaleElementReferenceException [as 别名]
def set_element_focus(self, element):
        """
        [Internal]

        Sets focus on element.

        :param element: Selenium element
        :type element: Selenium object

        Usage:

        >>> #Defining the element:
        >>> element = lambda: self.driver.find_element_by_id("example_id")
        >>> #Calling the method
        >>> text = self.set_element_focus(element())
        """   
        try:
            self.driver.execute_script("window.focus(); arguments[0].focus();", element)
        except StaleElementReferenceException:
            print("********Element Stale set_element_focus*********")
            pass 
开发者ID:totvs,项目名称:tir,代码行数:23,代码来源:base.py

示例10: test_interact_with_found_elements

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import StaleElementReferenceException [as 别名]
def test_interact_with_found_elements(self):
		all_tfs = find_all(TextField())
		example_tf = None
		for text_field in all_tfs:
			try:
				id_ = text_field.web_element.get_attribute('id')
			except StaleElementReferenceException:
				# This may happen for found web elements in different iframes.
				# TODO: Improve this, eg. by adding a .getId() property to
				# TextField (/HTMLElement) which handles this problem.
				pass
			else:
				if id_ == 'exampleTextFieldId':
					example_tf = text_field
		self.assertIsNotNone(example_tf)
		write("test_interact_with_found_elements", into=example_tf)
		self.assertEqual(
			"test_interact_with_found_elements",
			TextField("Example Text Field").value
		) 
开发者ID:mherrmann,项目名称:selenium-python-helium,代码行数:22,代码来源:test_find_all.py

示例11: wait_for_element_is_stale

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import StaleElementReferenceException [as 别名]
def wait_for_element_is_stale(element):
    """
    If you keep some references to elements from the old page lying around, then they will become stale once the DOM refreshes, and stale elements cause selenium to raise a
    StaleElementReferenceException if you try and interact with them. So just poll one until you get an error. Bulletproof!
    @see http://www.obeythetestinggoat.com/how-to-get-selenium-to-wait-for-page-load-after-a-click.html
    :param element:
    :return:
    """
    # link = browser.find_element_by_link_text('my link')
    # link.click()

    def has_gone_stale():
        try:
            # poll the link with an arbitrary call
            value = element.text
            # always return false and fool PyCharm check of unused var 'value'
            return value == "" and value != ""
        except StaleElementReferenceException:
            return True

    wait_for(has_gone_stale) 
开发者ID:timelyart,项目名称:Kairos,代码行数:23,代码来源:tools.py

示例12: get_body_text

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import StaleElementReferenceException [as 别名]
def get_body_text(driver,
        exponential_multiplier=cfg_wait_exponential_multiplier,
        exponential_max=cfg_wait_exponential_max,
        stop_max_attempt=cfg_retry_stop_max_attempt):
    @retry(
        wait_exponential_multiplier=exponential_multiplier,
        wait_exponential_max=exponential_max,
        stop_max_attempt_number=stop_max_attempt)
    def _get_body_text(driver):
        try:
            e = wait_for_xpath_presence(driver, "//body")
        except StaleElementReferenceException:
            a_nice_refresh(driver)
            e = wait_for_xpath_presence(driver, "//*")
            raise StaleElementReferenceException
        return e.get_attribute("outerHTML")
    return _get_body_text(driver)


# Subbornly clicks on the elements which run away from the DOM 
开发者ID:target,项目名称:winnaker,代码行数:22,代码来源:helpers.py

示例13: click_stubborn

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import StaleElementReferenceException [as 别名]
def click_stubborn(driver, e, xpath):
    logging.debug("Starting stubborn clicks")
    MAX_ATTEMPT = 6
    attempt = 0
    while attempt < MAX_ATTEMPT:
        try:
            for i in range(10):
                attempt += 1
                e.click()
                break
            # breaks if no exception happens
            break
        except StaleElementReferenceException:
            a_nice_refresh(driver)
            e = wait_for_xpath_presence(driver, xpath)
        except WebDriverException:
            break
    return e 
开发者ID:target,项目名称:winnaker,代码行数:20,代码来源:helpers.py

示例14: chat_history

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import StaleElementReferenceException [as 别名]
def chat_history():
    text_bubbles = driver.find_elements_by_class_name("message-out")  # message-in = receiver, message-out = sender
    tmp_queue = []

    try:
        for bubble in text_bubbles:
            msg_texts = bubble.find_elements_by_class_name("copyable-text")
            for msg in msg_texts:
                tmp_queue.append(msg.text.lower())

        if len(tmp_queue) > 0:
            return tmp_queue[-1]  # Send last message in list

    except StaleElementReferenceException as e:
        print(str(e))
        # Something went wrong, either keep polling until it comes back or figure out alternative

    return False 
开发者ID:jctissier,项目名称:whatsapp-assistant-bot,代码行数:20,代码来源:whatsapp_assistant_bot.py

示例15: select_tag

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import StaleElementReferenceException [as 别名]
def select_tag(context, tag):
    wait_for_user_alert_to_disapear(context)
    expand_side_nav(context)

    # try this multiple times as there are some race conditions
    try_again = 2
    success = False
    while (not success) and (try_again > 0):
        try:
            find_element_by_css_selector(context, '#tag-%s' % tag)

            e = find_element_by_css_selector(context, '#tag-%s .tag-label' % tag)
            e.click()

            find_element_by_css_selector(context, ".mail-list-entry__item[href*='%s']" % tag)
            success = True
        except (TimeoutException, StaleElementReferenceException):
            pass
        finally:
            try_again -= 1

    assert success 
开发者ID:pixelated,项目名称:pixelated-user-agent,代码行数:24,代码来源:tag_list.py


注:本文中的selenium.common.exceptions.StaleElementReferenceException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。