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


Python expected_conditions.presence_of_all_elements_located方法代码示例

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


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

示例1: find_elements

# 需要导入模块: from selenium.webdriver.support import expected_conditions [as 别名]
# 或者: from selenium.webdriver.support.expected_conditions import presence_of_all_elements_located [as 别名]
def find_elements(browser, locator, locator_strategy=By.CSS_SELECTOR, except_on_timeout=True, visible=False, delay=CHECK_IF_EXISTS_TIMEOUT):
    if except_on_timeout:
        if visible:
            elements = WebDriverWait(browser, delay).until(
                ec.visibility_of_all_elements_located((locator_strategy, locator)))
        else:
            elements = WebDriverWait(browser, delay).until(
                ec.presence_of_all_elements_located((locator_strategy, locator)))
        return elements
    else:
        try:
            if visible:
                elements = WebDriverWait(browser, delay).until(
                    ec.visibility_of_all_elements_located((locator_strategy, locator)))
            else:
                elements = WebDriverWait(browser, delay).until(
                    ec.presence_of_all_elements_located((locator_strategy, locator)))
            return elements
        except TimeoutException as e:
            log.debug(e)
            log.debug("Check your {} locator: {}".format(locator_strategy, locator))
            # print the session_id and url in case the element is not found
            # noinspection PyProtectedMember
            log.debug("In case you want to reuse session, the session_id and _url for current browser session are: {},{}".format(browser.session_id, browser.command_executor._url))
            return None 
开发者ID:timelyart,项目名称:Kairos,代码行数:27,代码来源:tv.py

示例2: wait_until_presence_of_all_elements_located

# 需要导入模块: from selenium.webdriver.support import expected_conditions [as 别名]
# 或者: from selenium.webdriver.support.expected_conditions import presence_of_all_elements_located [as 别名]
def wait_until_presence_of_all_elements_located(self, browser_instance,
                                                    locator_type, locator, timeout=5):
        try:
            WebDriverWait(browser_instance, int(timeout)).until(EC.presence_of_all_elements_located((BYCLASS[locator_type.strip().upper()], locator)))
            status = True
        except KeyError:
            print_error("The given locator_type - '{0}' does not match any of "
                        "the accepted locator_types.".format(locator_type))
            print_error("{0}, {1}, {2}, {3}, {4}, {5}, {6}, and {7} are the "
                        "accepted locator types.".format("id", "xpath", "link"
                                                         "class", "tag", "name",
                                                         "css_selector",
                                                         "partial_link"))
            status = "ERROR"
        except TimeoutException:
            print_error("Elements not present after {0} seconds".format(timeout))
            status = False
        except Exception as e:
            print_error("An Exception Ocurred: {0}".format(e))
            status = "ERROR"
        return status 
开发者ID:warriorframework,项目名称:warriorframework,代码行数:23,代码来源:wait_operations.py

示例3: wait_for_selector

# 需要导入模块: from selenium.webdriver.support import expected_conditions [as 别名]
# 或者: from selenium.webdriver.support.expected_conditions import presence_of_all_elements_located [as 别名]
def wait_for_selector(browser,
                      selector,
                      timeout=10,
                      visible=False,
                      single=False):
    wait = WebDriverWait(browser, timeout)
    if single:
        if visible:
            conditional = EC.visibility_of_element_located
        else:
            conditional = EC.presence_of_element_located
    else:
        if visible:
            conditional = EC.visibility_of_all_elements_located
        else:
            conditional = EC.presence_of_all_elements_located
    return wait.until(conditional((By.CSS_SELECTOR, selector))) 
开发者ID:vatlab,项目名称:sos-notebook,代码行数:19,代码来源:test_utils.py

示例4: _activate_toolbar

# 需要导入模块: from selenium.webdriver.support import expected_conditions [as 别名]
# 或者: from selenium.webdriver.support.expected_conditions import presence_of_all_elements_located [as 别名]
def _activate_toolbar(browser, name="Create%20Assignment"):
    def celltoolbar_exists(browser):
        return browser.execute_script(
            """
            return typeof $ !== "undefined" && $ !== undefined &&
                $("#view_menu #menu-cell-toolbar").find("[data-name=\'{}\']").length == 1;
            """.format(name))

    # wait for the view menu to appear
    _wait(browser).until(celltoolbar_exists)

    # activate the Create Assignment toolbar
    browser.execute_script(
        "$('#view_menu #menu-cell-toolbar').find('[data-name=\"{}\"]').find('a').click();".format(name)
    )

    # make sure the toolbar appeared
    if name == "Create%20Assignment":
        _wait(browser).until(
            EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".celltoolbar select")))
    elif name == "Edit%20Metadata":
        _wait(browser).until(
            EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".celltoolbar button"))) 
开发者ID:jupyter,项目名称:nbgrader,代码行数:25,代码来源:test_create_assignment.py

示例5: _wait_until_elements_are_visible_by_locator

# 需要导入模块: from selenium.webdriver.support import expected_conditions [as 别名]
# 或者: from selenium.webdriver.support.expected_conditions import presence_of_all_elements_located [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

示例6: get_data

# 需要导入模块: from selenium.webdriver.support import expected_conditions [as 别名]
# 或者: from selenium.webdriver.support.expected_conditions import presence_of_all_elements_located [as 别名]
def get_data(self):
        while True:
            # 获取 ListView
            items = self.wait.until(EC.presence_of_all_elements_located((By.ID, 'com.tencent.mm:id/eew')))
            # 滑动
            self.driver.swipe(self.start_x, self.start_y, self.end_x, self.end_y, 2000)
            #遍历获取每个List数据
            for item in items:
                moment_text = item.find_element_by_id('com.tencent.mm:id/kt').text
                day_text = item.find_element_by_id('com.tencent.mm:id/eke').text
                month_text = item.find_element_by_id('com.tencent.mm:id/ekf').text
                print('抓取到小帅b朋友圈数据: %s' % moment_text)
                print('抓取到小帅b发布时间: %s月%s' % (month_text, day_text)) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:15,代码来源:wechat_moment.py

示例7: getAllFriendList

# 需要导入模块: from selenium.webdriver.support import expected_conditions [as 别名]
# 或者: from selenium.webdriver.support.expected_conditions import presence_of_all_elements_located [as 别名]
def getAllFriendList(broswer, userID, pageNum, friendSet, currentLevel):
    try:
        broswer.get('https://www.zhihu.com%s?page=%s' % (userID, pageNum))
        WebDriverWait(broswer, 10).until(
            expected_conditions.presence_of_all_elements_located((By.CSS_SELECTOR, '.UserLink-link')))
    except:
        print('getAllFriendList异常')
    else:
        bsObj = BeautifulSoup(broswer.page_source, 'html.parser')
        elts = bsObj.findAll('a', {'class':'UserLink-link'})
        for elt in elts:
            img = elt.find('img')
            if img:
                friendSet.add(elt)
                print('......*' * currentLevel, 'https://www.zhihu.com%s' % (elt.attrs.get('href', 'no data'))) 
开发者ID:yhswjtuILMARE,项目名称:Machine-Learning-Study-Notes,代码行数:17,代码来源:ZhiHuUtil.py

示例8: scroll

# 需要导入模块: from selenium.webdriver.support import expected_conditions [as 别名]
# 或者: from selenium.webdriver.support.expected_conditions import presence_of_all_elements_located [as 别名]
def scroll(self):
        while True:
            # 当前页面显示的所有状态
            items = self.wait.until(EC.presence_of_all_elements_located((By.ID, 'com.xingin.xhs:id/a1z')))
            # 遍历每条状态
            for item in items:
                try:
                    # 昵称
                    nickname = item.find_element_by_id('com.xingin.xhs:id/bhs').get_attribute('text')
                    # 正文
                    content = item.find_element_by_id('com.xingin.xhs:id/anl').get_attribute('text')
                    # 日期
                    date = item.find_element_by_id('com.xingin.xhs:id/ask').get_attribute('text')
                    # 处理日期
                    date = self.processor.date(date)
                    print(nickname, content, date)
                    data = {
                        'nickname': nickname,
                        'content': content,
                        'date': date,
                    }
                    # 插入MongoDB
                    self.collection.update({'nickname': nickname, 'content': content}, {'$set': data}, True)
                    sleep(SCROLL_SLEEP_TIME)
                except NoSuchElementException:
                    pass
            # 上滑
            self.driver.swipe(FLICK_START_X, FLICK_START_Y + FLICK_DISTANCE, FLICK_START_X, FLICK_START_Y) 
开发者ID:HhhuYu,项目名称:xhs_simple_crawler,代码行数:30,代码来源:xhs_app.py

示例9: view_score

# 需要导入模块: from selenium.webdriver.support import expected_conditions [as 别名]
# 或者: from selenium.webdriver.support.expected_conditions import presence_of_all_elements_located [as 别名]
def view_score(self):
        self.safe_click(rules['score_entry'])
        titles = ["登录", "阅读文章", "视听学习", "文章学习时长", 
                "视听学习时长", "每日答题", "每周答题", "专项答题", 
                "挑战答题", "订阅", "收藏", "分享", "发表观点"]
        score_list = self.wait.until(EC.presence_of_all_elements_located((By.XPATH, rules['score_list'])))
        for t, score in zip(titles, score_list):
            s = score.get_attribute("name")
            self.score[t] = tuple([int(x) for x in re.findall(r'\d+', s)])

        # print(self.score)
        for i in self.score:
            logger.debug(f'{i}, {self.score[i]}')
        self.safe_back('score -> home') 
开发者ID:kessil,项目名称:AutoXue,代码行数:16,代码来源:__init__.py

示例10: _wait_for

# 需要导入模块: from selenium.webdriver.support import expected_conditions [as 别名]
# 或者: from selenium.webdriver.support.expected_conditions import presence_of_all_elements_located [as 别名]
def _wait_for(driver,
              locator_type,
              locator,
              timeout=10,
              visible=False,
              single=False):
    """Waits `timeout` seconds for the specified condition to be met. Condition is
    met if any matching element is found. Returns located element(s) when found.
    Args:
        driver: Selenium web driver instance
        locator_type: type of locator (e.g. By.CSS_SELECTOR or By.TAG_NAME)
        locator: name of tag, class, etc. to wait for
        timeout: how long to wait for presence/visibility of element
        visible: if True, require that element is not only present, but visible
        single: if True, return a single element, otherwise return a list of matching
        elements
    """
    wait = WebDriverWait(driver, timeout)
    if single:
        if visible:
            conditional = EC.visibility_of_element_located
        else:
            conditional = EC.presence_of_element_located
    else:
        if visible:
            conditional = EC.visibility_of_all_elements_located
        else:
            conditional = EC.presence_of_all_elements_located
    return wait.until(conditional((locator_type, locator))) 
开发者ID:vatlab,项目名称:sos-notebook,代码行数:31,代码来源:test_utils.py

示例11: _wait_until_elements_are_visible_by_locator

# 需要导入模块: from selenium.webdriver.support import expected_conditions [as 别名]
# 或者: from selenium.webdriver.support.expected_conditions import presence_of_all_elements_located [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:pixelated,项目名称:pixelated-user-agent,代码行数:6,代码来源:common.py

示例12: get_screenshot

# 需要导入模块: from selenium.webdriver.support import expected_conditions [as 别名]
# 或者: from selenium.webdriver.support.expected_conditions import presence_of_all_elements_located [as 别名]
def get_screenshot(
        self, url: str, element_name: str, user: "User", retries: int = SELENIUM_RETRIES
    ) -> Optional[bytes]:
        driver = self.auth(user)
        driver.set_window_size(*self._window)
        driver.get(url)
        img: Optional[bytes] = None
        logger.debug("Sleeping for %i seconds", SELENIUM_HEADSTART)
        time.sleep(SELENIUM_HEADSTART)
        try:
            logger.debug("Wait for the presence of %s", element_name)
            element = WebDriverWait(driver, 10).until(
                EC.presence_of_element_located((By.CLASS_NAME, element_name))
            )
            logger.debug("Wait for .loading to be done")
            WebDriverWait(driver, 60).until_not(
                EC.presence_of_all_elements_located((By.CLASS_NAME, "loading"))
            )
            logger.info("Taking a PNG screenshot")
            img = element.screenshot_as_png
        except TimeoutException:
            logger.error("Selenium timed out")
        except WebDriverException as ex:
            logger.error(ex)
            # Some webdrivers do not support screenshots for elements.
            # In such cases, take a screenshot of the entire page.
            img = driver.screenshot()  # pylint: disable=no-member
        finally:
            self.destroy(driver, retries)
        return img 
开发者ID:apache,项目名称:incubator-superset,代码行数:32,代码来源:screenshots.py

示例13: Elems

# 需要导入模块: from selenium.webdriver.support import expected_conditions [as 别名]
# 或者: from selenium.webdriver.support.expected_conditions import presence_of_all_elements_located [as 别名]
def Elems(self,css:str) -> [WebElement]:
        return self._wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,css))) 
开发者ID:MikimotoH,项目名称:DLink_Harvester,代码行数:4,代码来源:harvest_utils.py

示例14: _wait_for_modal

# 需要导入模块: from selenium.webdriver.support import expected_conditions [as 别名]
# 或者: from selenium.webdriver.support.expected_conditions import presence_of_all_elements_located [as 别名]
def _wait_for_modal(browser):
    _wait(browser).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".modal-dialog"))) 
开发者ID:jupyter,项目名称:nbgrader,代码行数:4,代码来源:test_validate_assignment.py

示例15: _wait_for_modal

# 需要导入模块: from selenium.webdriver.support import expected_conditions [as 别名]
# 或者: from selenium.webdriver.support.expected_conditions import presence_of_all_elements_located [as 别名]
def _wait_for_modal(browser):
    _wait(browser).until(
        EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".modal-dialog"))) 
开发者ID:jupyter,项目名称:nbgrader,代码行数:5,代码来源:test_create_assignment.py


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