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


Python WebDriverWait.until方法代码示例

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


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

示例1: process_request

# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import until [as 别名]
 def process_request(self, request, spider):
     if request.meta.has_key("PhantomJS"):  #
         logging.info("[PID:%s] PhantomJS Requesting: %s" % (os.getpid(), request.url))
         proxy = self.proxyFactory.getRandomProxy()
         if proxy:
             driver = self.getProxiedDriver(proxy)
         else:
             driver = self.getDriver()
         try:
             driver.get(request.url)
             wait = WebDriverWait(driver, 10)  # 设置超时时长
             wait.until(EC.visibility_of_element_located((By.ID, "jd-price")))  # 直到jd-price元素被填充之后才算请求完成
             content = driver.page_source.encode("utf-8")
             url = driver.current_url.encode("utf-8")
             if content is None or content.strip() == "" or content == "<html><head></head><body></body></html>":  #
                 logging.debug("[PID:%s] PhantomJS Request failed!" % os.getpid())
                 return HtmlResponse(request.url, encoding="utf-8", status=503, body="")
             else:  #
                 logging.debug("[PID:%s]PhantomJS Request success!" % os.getpid())
                 return HtmlResponse(url, encoding="utf-8", status=200, body=content)
         except Exception as e:
             errorStack = traceback.format_exc()
             logging.error("[PID:%s] PhantomJS request exception! exception info:%s" % (os.getpid(), errorStack))
             return HtmlResponse(request.url, encoding="utf-8", status=503, body="")
         finally:
             driver.quit()
开发者ID:BB-H,项目名称:realmai,代码行数:28,代码来源:middlewares.py

示例2: wait_and_find

# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import until [as 别名]
def wait_and_find(browser, by, target, message=None, timeout=10, poll=0.5, allow_timeout=False):
    """
    Wait until some element is visible on the page (assume DOM is ready by then).

    Wraps selenium.webdriver.support.wait() API.

    http://selenium.googlecode.com/svn/trunk/docs/api/py/webdriver_support/selenium.webdriver.support.wait.html#module-selenium.webdriver.support.wait

    :param by: WebDriver By.XXX target

    :param target: CSS selector or such

    :param message: Error message to show if the element is not found

    :param allow_timeout: Let timeout exceptions through, otherwise invoke ipdb in SELENIUM_DEBUG_MODE
                          if element is not found
    """

    if not message:
        message = "Waiting for element: %s" % target

    waitress = WebDriverWait(browser, timeout, poll)
    matcher = lambda driver: driver.find_element(by, target)

    if allow_timeout:
        # Waitress throws an exception if element is not found within the timeout
        try:
            waitress.until(matcher, message)
        except Exception:
            return None
    else:
        waitress.until(matcher, message)

    elem = browser.find_element(by, target)
    return elem
开发者ID:gitram,项目名称:scrapekit,代码行数:37,代码来源:seleniumhelper.py

示例3: test_sort_routes

# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import until [as 别名]
 def test_sort_routes(self):
     wait = WebDriverWait(self.driver, 15)
     self.click_first_nearby_stop('Taipei Station')
     wait.until(
         lambda driver: self.driver.find_element_by_id('nexti.android.bustaipei:id/menu_passby_sort')
     ).click()
     sleep(0.5)
     estimates = self.driver.find_elements_by_id('nexti.android.bustaipei:id/text_estimate')
     current_estimate = 0
     is_depart = False
     serv_over = False
     for estimate in estimates:
         if is_depart:
             self.assertEqual(estimate.text, 'Depart')
         elif serv_over:
             self.assertEqual(estimate.text, 'Serv Over')
         if estimate.text == 'Depart':
             is_depart = True
             continue
         elif estimate.text == 'Serv Over':
             serv_over = True
             continue
         elif estimate.text == 'Approach':
             continue
         match = re.search('(\d{0,2}) min', estimate.text)
         next_estimate = int(match.group(1))
         self.assertLessEqual(current_estimate, next_estimate)
         current_estimate = next_estimate
开发者ID:gcaaa31928,项目名称:BusTrackerTaipeiAppiumTesting,代码行数:30,代码来源:test_nearby_page_stations.py

示例4: __init__

# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import until [as 别名]
    def __init__(self):
        name = ""
        pw = ""
        while((name == "") | (pw == "")):
            name = input("Loginname: ")
            print("Login :", name)
            pw = input("Password: ")#TODO: nicer password taking
            print("PW :", pw)

        dcap = dict(DesiredCapabilities.PHANTOMJS)
        dcap["phantomjs.page.settings.userAgent"] = (
           "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 (KHTML, like Gecko) Chrome/15.0.87")

        self.driver = webdriver.PhantomJS(desired_capabilities=dcap, service_args=['--ignore-ssl-errors=true'])

        #goto isis page because direct access is not permitted
        self.driver.get("https://isis.tu-berlin.de/")

        #wait until page is up
        wait = WebDriverWait(self.driver, 10)
        wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.content")))

        #click shibbolethbutton to go to login page
        self.driver.find_element_by_id('shibbolethbutton').click()


        # Fill the login form and submit it
        self.driver.find_element_by_name('j_username').send_keys(name)
        self.driver.find_element_by_id('password').send_keys(pw)
        self.driver.find_element_by_name('Submit').submit()
开发者ID:DopeforHope,项目名称:isisDataFetcher,代码行数:32,代码来源:mainTest.py

示例5: test_select_suggest

# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import until [as 别名]
    def test_select_suggest(self):
        self.driver.execute_script("mobile: OnScreenKeyboard.Disable")

        pivots = self.driver.find_elements_by_class_name("Windows.UI.Xaml.Controls.Primitives.PivotHeaderItem")
        pivots[1].click()

        waiter = WebDriverWait(self.driver, timeout=5)

        autosuggestion_box = waiter.until(EC.presence_of_element_located((By.ID, 'MySuggestBox')))
        autosuggestion_input = autosuggestion_box.find_element_by_class_name('Windows.UI.Xaml.Controls.TextBox')
        autosuggestion_input.send_keys('A')

        suggestions_list = waiter.until(EC.presence_of_element_located((By.XNAME, 'SuggestionsList')))
        suggestions = suggestions_list.find_elements_by_class_name('Windows.UI.Xaml.Controls.TextBlock')

        expected_text = 'A2'

        for suggest in suggestions:
            if suggest.text == expected_text:
                # When AutoSuggest is focused it moves whole view up
                # but it is not reflected coordinates that we get from driver,
                # instead of suggest.click() we will have to use Select pattern
                point = self.driver.execute_script('automation: GetClickablePoint', suggest)
                x, y = [float(v) for v in point.split(',')]
                ActionChains(self.driver).move_by_offset(x, y).click().perform()
                break

        assert expected_text == autosuggestion_input.text
开发者ID:meilke,项目名称:Winium.StoreApps,代码行数:30,代码来源:test_commands.py

示例6: _get_keyspace_shards

# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import until [as 别名]
 def _get_keyspace_shards(self):
   wait = WebDriverWait(self.driver, 10)
   wait.until(expected_conditions.visibility_of_element_located(
       (By.TAG_NAME, 'vt-keyspace-view')))
   keyspace_content = self.driver.find_element_by_tag_name('vt-keyspace-view')
   return [sh.text for sh in
           keyspace_content.find_elements_by_class_name('vt-serving-shard')]
开发者ID:mapbased,项目名称:vitess,代码行数:9,代码来源:vtctld_web_test.py

示例7: _attempt_download

# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import until [as 别名]
 def _attempt_download(self, query, offset):
     real_offset = self._calculate_real_offset(offset)
     real_offset = int(real_offset)
     dictionary = {AbsWebsiteCommonApi._QUERY_MASK: query, AbsWebsiteCommonApi._OFFSET_MASK: str(real_offset)}
     url = self._multiple_replace(dictionary, self.base_url)
     page_source = None
     for i in range(0, AbsWebsiteCommonApi._DOWNLOAD_TRY_NUMBER):
         time.sleep(AbsWebsiteCommonApi._CRAWL_DELAY)
         web_page = None
         try:
             web_page = webdriver.PhantomJS()
             web_page.get(url)
             wait = WebDriverWait(web_page, AbsWebsiteCommonApi._PAGE_LOAD_TIMEOUT)
             wait.until(self.test_page_loaded)
         except Exception as exception:
             print(str(exception))
             if web_page is not None:
                 web_page.close()
             page_source = None
             continue
         page_source = web_page.execute_script(AbsWebsiteCommonApi._JAVASCRIPT_GET_PAGE_SOURCE_CODE)
         web_page.close()
         self.inc_download()
         break
     if page_source is None:
         print("ERROR - Internet connection failure")
         os.kill(os.getpid(), signal.SIGUSR1)
     return page_source
开发者ID:fpbfabio,项目名称:estimation_methods,代码行数:30,代码来源:abs_website_common_api.py

示例8: Application

# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import until [as 别名]
class Application(object):

    def __init__(self, driver):
        self.wd = driver
        self.base_url = "http://localhost/"
        self.session = SessionHelper(self)
        self.movie = MovieHelper(self)
    #    self.wait = WaitHelper(self)
        self.wait = WebDriverWait(self.wd, 30)

    def wait_element_off(self, element):
        self.wait.until(staleness_of(element))

    def wait_element_on(self):
        wd = self.wd
        element = self.wait.until(presence_of_element_located((By.XPATH, "//div[@class='movie_box']")))
        if element != wd.find_element_by_xpath("//div[@class='movie_box']"):
            pass
        #self.session.logout()

    def open_add_movie_page(self):
        wd = self.wd
        wd.get(self.base_url + "/php4dvd/?go=add")

    def open_home_page(self):
        wd = self.wd
        wd.get(self.base_url + "/php4dvd/")

    def destroy(self):
        self.wd.quit()
开发者ID:Dananas732,项目名称:php4dvd_lyzlov,代码行数:32,代码来源:application.py

示例9: test_add_cart_items

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

        wait = WebDriverWait(self.driver, 5)

        for _ in xrange(NUMBER_OF_PRODUCTS):
            self.driver.get(STORE_PAGE)
            products = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".product.column")))
            products[0].click()
            add_to_cart_btn = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "button[value=\"Add To Cart\"]")))
            size_options = self.driver.find_elements_by_xpath("(.//select[@name=\"options[Size]\"]/option)[position() > 1]")
            if size_options:
                random.choice(size_options[1:]).click()

            before_add_item_quantity = int(self.driver.find_element_by_css_selector("#cart .quantity").text)
            add_to_cart_btn.click()
            wait.until(lambda driver: int(self.driver.find_element_by_css_selector("#cart .quantity").text) > before_add_item_quantity)

        self.driver.find_element_by_css_selector("a[href*=\"checkout\"]:nth-of-type(3)").click()
        wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "[name=\"confirm_order\"]")))

        shortcuts = self.driver.find_elements_by_css_selector(".shortcut")
        if shortcuts:
            for _ in xrange(len(shortcuts)):
                remove_btn = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "[name=\"remove_cart_item\"]")))
                remove_btn.click()
                wait.until(EC.staleness_of(remove_btn))
        else:
            self.driver.find_element_by_css_selector("[name=\"remove_cart_item\"]").click()

        checkout_wrapper = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#checkout-cart-wrapper em")))
        assert checkout_wrapper.text == "There are no items in your cart."
开发者ID:enelf,项目名称:joker,代码行数:33,代码来源:test_exercise_13_add_cart_items.py

示例10: _get_keyspaces

# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import until [as 别名]
 def _get_keyspaces(self):
     """Get list of all present keyspaces."""
     wait = WebDriverWait(self.driver, 10)
     wait.until(expected_conditions.visibility_of_element_located((By.TAG_NAME, "vt-dashboard")))
     dashboard_content = self.driver.find_element_by_tag_name("vt-dashboard")
     toolbars = dashboard_content.find_elements_by_class_name("vt-card-toolbar")
     return [t.find_element_by_class_name("vt-title").text for t in toolbars]
开发者ID:mattharden,项目名称:vitess,代码行数:9,代码来源:vtctld2_web_test.py

示例11: _get_keyspace_element

# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import until [as 别名]
 def _get_keyspace_element(self, keyspace_name):
   """Get a specific keyspace element given a keyspace name."""
   element_id = '%s-card' % keyspace_name
   wait = WebDriverWait(self.driver, self.WEBDRIVER_TIMEOUT_S)
   wait.until(expected_conditions.visibility_of_element_located(
       (By.ID, element_id)))
   return self.driver.find_element_by_id(element_id)
开发者ID:alainjobart,项目名称:vitess,代码行数:9,代码来源:vtctld_web_test.py

示例12: wait_element_load_end

# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import until [as 别名]
 def wait_element_load_end(self, element):
     wait = WebDriverWait(self.driver, waiting_time)
     try:
         wait.until(ec.presence_of_element_located(*element))
         wait.until(ec.element_to_be_clickable(*element))
     except:
         time.sleep(1)
开发者ID:Ken-Kei,项目名称:Automate,代码行数:9,代码来源:BasePage.py

示例13: test_check_countries

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

        wait = WebDriverWait(self.driver, 5)
        self.sign_in()
        self.driver.get(COUNTRIES_PAGE)
        current_countries = []
        not_null_zones_country_links = []
        country_rows = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".row")))

        for row in country_rows:
            country = row.find_element_by_css_selector("td:nth-child(5) a")
            current_countries.append(country.text)
            zones = row.find_element_by_css_selector("td:nth-child(6)")
            if int(zones.text) > 0:
                not_null_zones_country_links.append(country.get_attribute("href"))

        expected_countries = sorted(current_countries)
        self.assertListEqual(current_countries, expected_countries)

        for link in not_null_zones_country_links:
            self.driver.get(link)
            current_country_zones = [x.text for x in wait.until(EC.presence_of_all_elements_located(
                (By.XPATH, "(.//*[@id=\"table-zones\"]//td[3])[position() < last()]")
            ))]
            expected_country_zones = sorted(current_country_zones)
            self.assertListEqual(current_country_zones, expected_country_zones)
开发者ID:enelf,项目名称:joker,代码行数:28,代码来源:test_exercise_9_countries.py

示例14: test_login_internet_original

# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import until [as 别名]
    def test_login_internet_original(self):
        # arrange
        self.logger.info('Instantiating driver ...')
        self.logger.info('Wait time set to 5 seconds ...')
        wait = WebDriverWait(self.driver, 5)
        # d = EventFiringWebDriver(self.driver, ScreenshotListener())
        self.driver.get("http://the-internet.dev/login")

        # act
        self.logger.info('Filling in username')
        username = self.driver.find_element_by_id("username")
        username.clear()
        username.send_keys("tomsmith")

        self.logger.info('Filling in password')
        password = self.driver.find_element_by_id("password")
        password.clear()
        password.send_keys("SuperSecretPassword!")

        self.logger.info('Clicking the submit button')
        login_button = self.driver.find_element_by_id("submit")
        login_button.click()

        # assert
        self.logger.info('Waiting for logged in message on screen')
        wait.until(ec.text_to_be_present_in_element((By.ID, 'flash-messages'), "You logged into a secure area!"))
        logout = wait.until(ec.element_to_be_clickable((By.ID, 'logout')))
        self.logger.info('Clicking logout button')
        logout.click()
        self.logger.info('Waiting for username textfield on screen')
        wait.until(ec.element_to_be_clickable((By.ID, 'username')))
开发者ID:windwaker,项目名称:PythonPageObjects,代码行数:33,代码来源:test.py

示例15: add_service

# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import until [as 别名]
    def add_service(self):
        count = self.items_in_cart()
        Find(by=By.CSS_SELECTOR, value='.add-to-cart', context=self).click()

        if not self.item_is_sold_out():
            wait = WebDriverWait(self._driver, 10)
            wait.until(lambda x: count < self.items_in_cart())
开发者ID:ShinKaiRyuu,项目名称:Testing-MBA-SB,代码行数:9,代码来源:services_page.py


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