欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

WebDriverWait詳解

selenium.webdriver.support.wait.WebDriverWait

成都創(chuàng)新互聯(lián)公司是專業(yè)的涇源網(wǎng)站建設公司,涇源接單;提供網(wǎng)站建設、網(wǎng)站制作,網(wǎng)頁設計,網(wǎng)站設計,建網(wǎng)站,PHP網(wǎng)站建設等專業(yè)做網(wǎng)站服務;采用PHP框架,可快速的進行涇源網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!

先看下WebDriverWait的代碼

import time
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException

POLL_FREQUENCY = 0.5  # How long to sleep inbetween calls to the method
IGNORED_EXCEPTIONS = (NoSuchElementException,)  # exceptions ignored during calls to the method


class WebDriverWait(object):
    def __init__(self, driver, timeout, poll_frequency=POLL_FREQUENCY, ignored_exceptions=None):
        """Constructor, takes a WebDriver instance and timeout in seconds.

           :Args:
            - driver - Instance of WebDriver (Ie, Firefox, Chrome or Remote)
            - timeout - Number of seconds before timing out
            - poll_frequency - sleep interval between calls
              By default, it is 0.5 second.
            - ignored_exceptions - iterable structure of exception classes ignored during calls.
              By default, it contains NoSuchElementException only.

           Example:
            from selenium.webdriver.support.ui import WebDriverWait \n
            element = WebDriverWait(driver, 10).until(lambda x: x.find_element_by_id("someId")) \n
            is_disappeared = WebDriverWait(driver, 30, 1, (ElementNotVisibleException)).\ \n
                        until_not(lambda x: x.find_element_by_id("someId").is_displayed())
        """
        self._driver = driver
        self._timeout = timeout
        self._poll = poll_frequency
        # avoid the divide by zero
        if self._poll == 0:
            self._poll = POLL_FREQUENCY
        exceptions = list(IGNORED_EXCEPTIONS)
        if ignored_exceptions is not None:
            try:
                exceptions.extend(iter(ignored_exceptions))
            except TypeError:  # ignored_exceptions is not iterable
                exceptions.append(ignored_exceptions)
        self._ignored_exceptions = tuple(exceptions)

    def __repr__(self):
        return '<{0.__module__}.{0.__name__} (session="{1}")>'.format(
            type(self), self._driver.session_id)

    def until(self, method, message=''):
        """Calls the method provided with the driver as an argument until the \
        return value is not False."""
        screen = None
        stacktrace = None

        end_time = time.time() + self._timeout
        while True:
            try:
                value = method(self._driver)
                if value:
                    return value
            except self._ignored_exceptions as exc:
                screen = getattr(exc, 'screen', None)
                stacktrace = getattr(exc, 'stacktrace', None)
            time.sleep(self._poll)
            if time.time() > end_time:
                break
        raise TimeoutException(message, screen, stacktrace)

    def until_not(self, method, message=''):
        """Calls the method provided with the driver as an argument until the \
        return value is False."""
        end_time = time.time() + self._timeout
        while True:
            try:
                value = method(self._driver)
                if not value:
                    return value
            except self._ignored_exceptions:
                return True
            time.sleep(self._poll)
            if time.time() > end_time:
                break
        raise TimeoutException(message)

來看下傳的參數(shù):

driver: 傳入WebDriver實例
timeout: 超時時間,等待的最長時間(同時要考慮隱性等待時間)
poll_frequency: 調(diào)用until或 中的方法的間隔時間,默認是0.5
ignored_exceptions: 忽略的異常,如果在調(diào)用until或until_not的過程中拋出這個元組中的異常,則不中斷代碼,繼續(xù)等待,如果拋出的是這個元組外的異常,則中斷代碼,拋出異常。默認只有NoSuchElementException。
until method: 在等待期間,每隔一段時間調(diào)用這個傳入的方法,直到返回值不是False
message: 如果超時,拋出TimeoutException,將message傳入異常

until_not 與until相反,until是當某元素出現(xiàn)或什么條件成立則繼續(xù)執(zhí)行,until_not是當某元素消失或什么條件不成立則繼續(xù)執(zhí)行,參數(shù)也相同,不再贅述。


調(diào)用方法如下:

WebDriverWait(driver, 超時時長, 調(diào)用頻率, 忽略異常).until(可執(zhí)行方法, 超時時返回的信息)

 這里需要特別注意的是until或until_not中的可執(zhí)行方法method參數(shù),很多人傳入了WebElement對象,這是不正確的。在這里,你可以用selenium提供的 expected_conditions 模塊中的各種條件,也可以用WebElement的 is_displayed() 、is_enabled()、is_selected() 方法,或者用自己封裝的方法都可以







網(wǎng)頁題目:WebDriverWait詳解
鏈接分享:http://aaarwkj.com/article22/isggcc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供App設計移動網(wǎng)站建設、定制開發(fā)、關鍵詞優(yōu)化、網(wǎng)站制作Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運營
日本高清精品视频在线| 亚洲国产成人精品久久精品| 免费观看国产性生活片| 禁区正片免费看完整国产| 成人又黄又爽大片在线观看| 免费国产污网站在线观看| 日韩性生活视频免费播放| 91麻豆视频福利视频| 99久久久国产精品日本久久区一| 亚洲一区二区三区不卡伦理| 最新日韩一区二区在线| 亚洲二区三区四区在线| 亚洲熟妇av一区二区三区l| 午夜未满十八禁止观看| 午夜福利福利一区二区| 有码不卡中文字幕在线视频| 午夜啪视频免费在线观看| 欧美亚洲清纯唯美另类| 亚州欧美制服另类国产| 91薄丝激情在线播放| 亚洲邻家人妻一区二区| 国产日韩精品激情另类综合| 国产夫妻性生活国产视频| 亚洲综合国产中文字幕| 亚洲一区日韩精品电影| 日本免费91午夜视频| 日韩一区二区亚洲精品| 国产精品日韩经典中文字幕| 久久这里只有精品视频| 蜜臀视频一区二区在线播放| 日韩精品中文字幕人妻系列| 亚洲综合偷拍欧美一区日韩| 青青草视频在线好好热| avav男人天堂亚洲天堂| 久久亚洲女同第一区综合| 美女在线视频一区二区三区| av在线免费观看不卡| 日本韩国亚洲三级在线| 欧美中文字幕在线精品| 欧美曰韩国内精品中文| 免费毛片一区二区三区|