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


Python wait.WebDriverWait方法代码示例

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


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

示例1: wait_until_impl

# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def wait_until_impl(self, condition_fn, timeout_secs=10, interval_secs=0.5):
		if ismethod(condition_fn):
			is_bound = condition_fn.__self__ is not None
			args_spec = getfullargspec(condition_fn).args
			unfilled_args = len(args_spec) - (1 if is_bound else 0)
		else:
			if not isfunction(condition_fn):
				condition_fn = condition_fn.__call__
			args_spec = getfullargspec(condition_fn).args
			unfilled_args = len(args_spec)
		condition = \
			condition_fn if unfilled_args else lambda driver: condition_fn()
		wait = WebDriverWait(
			self.require_driver().unwrap(), timeout_secs,
			poll_frequency=interval_secs
		)
		wait.until(condition) 
开发者ID:mherrmann,项目名称:selenium-python-helium,代码行数:19,代码来源:__init__.py

示例2: loadmap

# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def loadmap(self):
        '''
        loadmap()
        Creates a browser object and loads the webpage.
        It sets up the map to the proper zoom level.

        Returns the browser on success, None on fail.
        '''
        browser = webdriver.PhantomJS(desired_capabilities={'phantomjs.page.settings.resourceTimeout': '20000'})
        browser.set_window_size(abovetustin_image_width, abovetustin_image_height)

        print("getting web page {}".format(self.url))
        browser.set_page_load_timeout(15)
        browser.get(self.url)

        # Need to wait for the page to load
        timeout = g_request_timeout
        print ("waiting for page to load...")
        wait = WebDriverWait(browser, timeout)
        element = wait.until(EC.element_to_be_clickable((By.CLASS_NAME,'vrsMenu')))
        self.browser = browser 
开发者ID:kevinabrandon,项目名称:AboveTustin,代码行数:23,代码来源:screenshot.py

示例3: __init__

# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def __init__(self, cookies_list):
        self.headers = {
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36',
        }
        option = ChromeOptions()
        option.add_experimental_option('excludeSwitches', ['enable-automation'])
        option.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})  # 不加载图片,加快访问速度
        option.add_argument('--headless')
        self.driver = webdriver.Chrome(options=option)
        self.driver.get('https://i.taobao.com/my_taobao.htm')
        for i in cookies_list:
            self.driver.add_cookie(cookie_dict=i)
        self.driver.get('https://i.taobao.com/my_taobao.htm')
        self.wait = WebDriverWait(self.driver, 10)  # 超时时长为10s

    # 模拟向下滑动浏览 
开发者ID:MyDataHomes,项目名称:Spider,代码行数:18,代码来源:spider.py

示例4: get_latest_wallpapers

# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def get_latest_wallpapers():
    browser = webdriver.PhantomJS(PHANTOMJS_PATH, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])
    today_date = time.strftime("%d+%b+%Y")  
    yesterday = datetime.now() - timedelta(days=1)
    yesterday_date = yesterday.strftime('%d+%b+%Y')
    first_page_url = 'http://www.espncricinfo.com/ci/content/image/?datefrom='+yesterday_date+'&dateupto='+today_date+';'
    browser.get(first_page_url)
    wait = WebDriverWait(browser, 10)
    wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "img-wrap")))
    time.sleep(2)
    # let's parse our html
    soup = BeautifulSoup(browser.page_source, "html.parser")
    images = soup.find_all('div', class_='picture')
    for image in images:
        url = "http://www.espncricinfo.com/" + image.find('a').get('href')
        print(url) 
开发者ID:DedSecInside,项目名称:Awesome-Scripts,代码行数:18,代码来源:scrape_espncricinfo.py

示例5: enter_concert

# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def enter_concert(self):
        self.login()
        try:
            if self.type == 1:  # detail.damai.cn
                locator = (By.XPATH, "/html/body/div[1]/div/div[3]/div[1]/a[2]/div")
            elif self.type == 2:  # piao.damai.cn
                locator = (By.XPATH, "/html/body/div[1]/div/ul/li[2]/div/label/a[2]")
            WebDriverWait(self.driver, self.total_wait_time, self.refresh_wait_time).until(
                EC.text_to_be_present_in_element(locator, self.nick_name))
            self.status = 1
            print("###登录成功###")
        except Exception as e:
            print(e)
            self.status = 0
            self.driver.quit()
            raise Exception("***错误:登录失败,请检查配置文件昵称或删除cookie.pkl后重试***") 
开发者ID:Entromorgan,项目名称:Autoticket,代码行数:18,代码来源:Autoticket.py

示例6: _init_browser

# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def _init_browser(self, browser, url_path=""):
        """
        Open browser with LEGO shop URL (index page if path not set)
        """
        self.shop_url = "https://www.lego.com/%s" % url_path

        self._load_driver(browser)

        # Selenium can't find some elements otherwise
        self.browser.maximize_window()

        self.browser.get(self.shop_url)

        # will wait to 5 sec for and ExpectedCondition success,
        # otherwise exception TimeoutException
        self.wait = WebDriverWait(self.browser, 5)

        self.browser_info() 
开发者ID:bittner,项目名称:lego-mindstorms-ev3-comparison,代码行数:20,代码来源:legoshop.py

示例7: get_selenium_js_html

# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def get_selenium_js_html(url):
    # browser = webdriver.PhantomJS(executable_path=r'D:\Python2.7\Scripts\phantomjs.exe')
    options = Options()
    options.add_argument('-headless')  # 无头参数
    driver = Chrome(executable_path='chromedriver', chrome_options=options)
    wait = WebDriverWait(driver, timeout=10)

    driver.get(url)
    time.sleep(3)
    # 执行js得到整个页面内容
    html = driver.execute_script("return document.documentElement.outerHTML")
    driver.close()
    return html


# 获取公众号文章内容 
开发者ID:feiweiwei,项目名称:WeixinSpider,代码行数:18,代码来源:spider_weixun_by_sogou.py

示例8: get_score

# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def get_score(self):
        login_url = r'https://pc.xuexi.cn/points/login.html.*'  # check if it has been login
        # score_url = r'https://pc.xuexi.cn/points/my-points.html.*'
        # if not re.match(login_url, self.driver.current_url) and not re.match(score_url, self.driver.current_url):
        #     self.driver.get('https://pc.xuexi.cn/points/my-points.html')
        # self.driver.switch_to.default_content()

        score_url = 'https://pc.xuexi.cn/points/my-points.html'

        try:
            self.driver.get(score_url)
        except selenium.common.exceptions.NoSuchWindowException as error:
            raise Exception(error)

        if re.match(login_url, self.driver.current_url):
            if not self.login():
                return []
        else:
            try:
                WebDriverWait(self.driver, 3).until(
                    expected_conditions.presence_of_element_located((By.XPATH, '//div[@class="my-points-card-text"]')))
            except Exception:
                return []

        score = []
        app.log(u'当前得分情况:')
        score_title = iter([u'每日登陆', u'阅读文章', u'观看视频', u'文章学习时长', u'视频学习时长'])
        for s in self.driver.find_elements_by_xpath('//div[@class="my-points-card-text"]'):
            app.log(u'%s: %s' % (next(score_title), s.text), printtime=False)
            try:
                score.append({'score': int(s.text.split('/')[0][:-1]), 'target': int(s.text.split('/')[1][:-1])})
            except Exception:
                pass

        return score 
开发者ID:zodiac182,项目名称:autoxuexi,代码行数:37,代码来源:xuexi.py

示例9: wait_until_element_is_invisible_by_locator

# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def wait_until_element_is_invisible_by_locator(context, locator_tuple,
                                               timeout=TIMEOUT_IN_S):
    wait = WebDriverWait(context.browser, timeout)
    wait.until(EC.invisibility_of_element_located(locator_tuple)) 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:6,代码来源:common.py

示例10: _wait_until_elements_are_visible_by_locator

# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def _wait_until_elements_are_visible_by_locator(context, locator_tuple,
                                                timeout=TIMEOUT_IN_S):
    wait = WebDriverWait(context.browser, timeout)
    wait.until(EC.presence_of_all_elements_located(locator_tuple))
    return context.browser.find_elements(locator_tuple[0], locator_tuple[1]) 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:7,代码来源:common.py

示例11: _wait_until_element_is_visible_by_locator

# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def _wait_until_element_is_visible_by_locator(context, locator_tuple,
                                              timeout=TIMEOUT_IN_S):
    wait = WebDriverWait(context.browser, timeout)
    wait.until(EC.visibility_of_element_located(locator_tuple))
    return context.browser.find_element(locator_tuple[0], locator_tuple[1]) 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:7,代码来源:common.py

示例12: wait_for_condition

# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def wait_for_condition(context, predicate_func, timeout=TIMEOUT_IN_S,
                       poll_frequency=0.1):
    wait = WebDriverWait(context.browser, timeout,
                         poll_frequency=poll_frequency)
    wait.until(predicate_func) 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:7,代码来源:common.py

示例13: wait_until_button_is_visible

# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def wait_until_button_is_visible(context, title, timeout=TIMEOUT_IN_S):
    wait = WebDriverWait(context.browser, timeout)
    locator_tuple = (By.XPATH, ("//%s[contains(.,'%s')]" % ('button', title)))
    wait.until(EC.visibility_of_element_located(locator_tuple)) 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:6,代码来源:common.py

示例14: login

# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def login(self):
        """登陆模块"""

        self.driver.get('https://passport.damai.cn/login')
        # WebDriverWait(self.driver, 10).until(
        #     EC.presence_of_element_located((By.ID, 'alibaba-login-box')))
        # self.driver.switch_to.frame('alibaba-login-box')
        # self.driver.find_element_by_xpath('//*[@id="fm-login-id"]').send_keys(self.phone_num)
        # self.driver.find_element_by_xpath('//*[@id="fm-login-password"]').send_keys(self.passwd)

        WebDriverWait(self.driver, 3000).until(
            EC.presence_of_element_located((By.XPATH, '//a[@data-spm="duserinfo"]/div')))
        print('登陆成功')
        user_name = self.driver.find_element_by_xpath('//a[@data-spm="duserinfo"]/div').text
        print('账号:', user_name) 
开发者ID:TinaryTree,项目名称:damaiTi9,代码行数:17,代码来源:main.py

示例15: detail_page_auto

# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def detail_page_auto(self):
        """详情页自动"""

        self.driver.get('https://detail.damai.cn/item.htm?id=593089517773')
        WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located((By.XPATH, '//button[@data-spm="dconfirm"]')))

        dconfirm_button = self.driver.find_element_by_xpath('//button[@data-spm="dconfirm"]')
        while dconfirm_button.get_attribute('class') == 'privilege_sub disabled':
            print(dconfirm_button.get_attribute('class'), '确定按钮无法点击,刷新页面')
            self.driver.refresh()
            WebDriverWait(self.driver, 10).until(
                EC.presence_of_element_located((By.XPATH, '//button[@data-spm="dconfirm"]')))
            try:
                dconfirm_button = self.driver.find_element_by_xpath('//button[@data-spm="dconfirm"]')
            except Exception as e:
                print('寻找按钮失败', e)

        self.driver.find_element_by_css_selector("#privilege_val").send_keys(self.dotakey)
        dconfirm_button.click()
        if self.quantity != 1:
            try:
                self.driver.find_element_by_xpath(
                    '//a[@class="cafe-c-input-number-handler cafe-c-input-number-handler-up"]').click()
            except Exception as e:
                print("未成功点击+号", e)
        self.driver.find_element_by_xpath(f'//div[@class="select_right_list"]/div[{self.round}]/span[2]').click()
        dbuy_button = self.driver.find_element_by_xpath('//div[@data-spm="dbuy"]')
        print('寻找按钮:', dbuy_button.text)
        dbuy_button.click() 
开发者ID:TinaryTree,项目名称:damaiTi9,代码行数:32,代码来源:main.py


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