• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.find_element函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中selenic.util.find_element函数的典型用法代码示例。如果您正苦于以下问题:Python find_element函数的具体用法?Python find_element怎么用?Python find_element使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: step_impl

def step_impl(context, choice):
    driver = context.driver
    util = context.util

    class_name = None
    if choice == "a placeholder":
        class_name = "_placeholder"
    elif choice == "text":
        class_name = "title"
    else:
        raise ValueError("unknown choice: " + choice)

    ActionChains(driver)\
        .click(util.find_element((By.CLASS_NAME, class_name))) \
        .perform()

    # Because we use the keyboard, the caret is our reference
    caret = util.find_element((By.CLASS_NAME, "_wed_caret"))

    # Mock it. The caret could move or disappear.
    trigger = Trigger()
    trigger.location = caret.location
    trigger.size = caret.size
    trigger.size["width"] = 0

    ActionChains(driver) \
        .key_down(Keys.CONTROL) \
        .send_keys("/") \
        .key_up(Keys.CONTROL) \
        .perform()

    context.context_menu_trigger = trigger
开发者ID:keisetsu,项目名称:wed,代码行数:32,代码来源:context_menu.py


示例2: context_choices_insert

def context_choices_insert(context, exists, kind):
    util = context.util

    exists = True if exists == "contains" else False

    search_for = None
    if kind == "inserting new elements":
        search_for = "^Create new [^ ]+$"
    elif kind == "creating elements before the selected element":
        search_for = "^Create new .+? before"
    elif kind == "creating elements after the selected element":
        search_for = "^Create new .+? after"
    elif kind == "wrapping text in new elements":
        search_for = "^Wrap in "
    else:
        raise ValueError("can't search for choices of this kind: " + kind)

    if exists:
        count = len(util.find_descendants_by_text_re(".wed-context-menu",
                                                     search_for))
        assert_not_equal(count, 0, "there should be options")
    else:
        # We first need to make sure the menu is up because
        # find_descendants_by_text_re will return immediately.
        util.find_element((By.CLASS_NAME, "wed-context-menu"))
        count = len(util.find_descendants_by_text_re(".wed-context-menu",
                                                     search_for, True))
        assert_equal(count, 0, "there should not be options")
开发者ID:bennettbuchanan,项目名称:wed,代码行数:28,代码来源:context_menu.py


示例3: step_impl

def step_impl(context):
    driver = context.driver
    util = context.util
    element = util.find_element((By.CSS_SELECTOR, ".title"))

    rect = driver.execute_script("""
    var title = arguments[0];
    var text = title.childNodes[1]; // At index 0 is the opening label.
    var range = title.ownerDocument.createRange();
    range.setStart(text, 0);
    range.setEnd(text, 1);
    // Just returning does not work with IEDriver...
    // return range.getBoundingClientRect();
    var rect = range.getBoundingClientRect();
    var ret = {};
    for (var x in rect)
        ret[x] = rect[x];
    return ret;
    """, element)

    last_click = {"left": round(rect["left"]) + 2,
                  "top": int(rect["top"] + rect["height"] / 2)}

    ActionChains(driver) \
        .move_to_element_with_offset(context.origin_object, last_click["left"],
                                     last_click["top"]) \
        .click() \
        .perform()

    context.last_click = last_click
开发者ID:bennettbuchanan,项目名称:wed,代码行数:30,代码来源:caret.py


示例4: step_impl

def step_impl(context, what):
    driver = context.driver
    util = context.util

    parent = util.find_element((By.CSS_SELECTOR, ".title"))
    label = parent.find_element_by_css_selector(".__start_label._title_label")

    if label.is_displayed():
        ActionChains(driver) \
            .click(label) \
            .perform()
    else:
        ActionChains(driver) \
            .move_to_element_with_offset(parent, 1, 1) \
            .click() \
            .perform()

    # We need to find the text inside the title element
    text = util.get_text_excluding_children(parent)
    start_index = text.find(what)
    assert_true(start_index >= 0, "should have found the text")
    if start_index > 0:
        util.send_keys(parent,
                       # Move the caret to the start of the selection
                       # we want.
                       [Keys.ARROW_RIGHT] * (start_index +
                                             1 if label.is_displayed() else 0))

    start = wedutil.caret_selection_pos(driver)
    util.send_keys(parent,
                   # Move to the end of the selection we want.
                   [Keys.ARROW_RIGHT] * len(what))
    end = wedutil.caret_selection_pos(driver)

    # We don't want to be too close to the edge to handle a problem when
    # labels are. The problem is that when the labels are invisible they
    # have 0 width and it is possible at least that the caret could be
    # put over the invisible label. (That is, instead of the caret being
    # put after the invisible start label, it would be put before the
    # invisible start label.) When a user selects manually, the visual
    # feedback tends to prevent this. In testing, we achieve the same
    # through shifting the boundaries inwards a bit.
    #
    # Note that we've deemed it unnecessary to change the
    # caret/selection code of wed to prevent the caret from moving over
    # an invisible label. The fix would be rather complicated but
    # selecting text by mouse when labels are invisible is a bit dodgy
    # **at any rate**, and we're not going to work around this
    # dodginess. For now, at least.
    start["left"] += 5
    end["left"] -= 5

    select_text(context, start, end)
    assert_equal(util.get_selection_text(), what,
                 "the selected text should be what we wanted to select")
    context.selection_parent = parent
    context.caret_screen_position = wedutil.caret_screen_pos(driver)
    context.element_to_test_for_text = parent
开发者ID:lddubeau,项目名称:wed,代码行数:58,代码来源:caret.py


示例5: context_menu_on_start_label_of_top_element

def context_menu_on_start_label_of_top_element(context):
    driver = context.driver
    util = context.util

    button = util.find_element((By.CSS_SELECTOR,
                                ".__start_label ._element_name"))
    ActionChains(driver)\
        .context_click(button)\
        .perform()
开发者ID:bennettbuchanan,项目名称:wed,代码行数:9,代码来源:context_menu.py


示例6: on_placeholder

def on_placeholder(context):
    driver = context.driver
    util = context.util

    placeholder = util.find_element((By.CLASS_NAME, "_placeholder"))
    ActionChains(driver) \
        .context_click(placeholder) \
        .perform()
    context.context_menu_trigger = placeholder
开发者ID:keisetsu,项目名称:wed,代码行数:9,代码来源:context_menu.py


示例7: context_menu_on_start_label_of_top_element

def context_menu_on_start_label_of_top_element(context):
    driver = context.driver
    util = context.util

    button = util.find_element((By.CLASS_NAME, "_start_button"))
    ActionChains(driver)\
        .context_click(button)\
        .perform()
    context.context_menu_trigger = button
开发者ID:keisetsu,项目名称:wed,代码行数:9,代码来源:context_menu.py


示例8: context_menu_on_end_label_of_element

def context_menu_on_end_label_of_element(context):
    driver = context.driver
    util = context.util

    button = util.find_element((By.CSS_SELECTOR, "._end_button._p_label"))
    ActionChains(driver)\
        .context_click(button)\
        .perform()
    context.context_menu_trigger = button
开发者ID:keisetsu,项目名称:wed,代码行数:9,代码来源:context_menu.py


示例9: context_menu_on_text

def context_menu_on_text(context):
    driver = context.driver
    util = context.util

    element = util.find_element((By.CLASS_NAME, "title"))
    ActionChains(driver)\
        .move_to_element(element)\
        .context_click()\
        .perform()
    context.context_menu_trigger = element
开发者ID:keisetsu,项目名称:wed,代码行数:10,代码来源:context_menu.py


示例10: step_impl

def step_impl(context, choice):
    driver = context.driver
    util = context.util

    class_name = None
    if choice == "a placeholder":
        parent, where = driver.execute_script("""
        var $ph = jQuery("._placeholder");
        var $parent = $ph.closest("._real");
        return [$parent[0], $ph[0]];
        """)
    elif choice == "text":
        where = util.find_element((By.CLASS_NAME, "title"))
        parent = where
    else:
        raise ValueError("unknown choice: " + choice)

    max_tries = 5
    while True:
        # IF YOU CHANGE THIS, CHANGE THE TRIGGER
        wedutil.click_until_caret_in(util, where)
        util.ctrl_equivalent_x("/")
        try:
            # We don't want to check too fast so we do use an explicit
            # wait by way of ``util``.
            util.find_element((By.CLASS_NAME, "wed-context-menu"))
            # If we get here, the menu exists.
            break
        except TimeoutException:
            # The menu did not come up. Probably something messed up
            # the caret between ``click_until_caret_in`` and
            # ``ctrl_equivalent_x``. Try again or decide that it just
            # won't happen.
            max_tries -= 1
            if max_tries == 0:
                raise Exception("tried multiple times to bring up "
                                "the contextual menu, but was "
                                "unsuccessful")

    # THIS TRIGGER WORKS ONLY BECAUSE OF .click(where) above.
    context.context_menu_trigger = Trigger(util, where)
    context.context_menu_for = parent
开发者ID:bennettbuchanan,项目名称:wed,代码行数:42,代码来源:context_menu.py


示例11: user_clicks_outside_context_menu

def user_clicks_outside_context_menu(context):
    driver = context.driver
    util = context.util

    title = util.find_element((By.CLASS_NAME, "title"))
    # This simulates a user whose hand is not completely steady.
    ActionChains(driver)\
        .move_to_element(title)\
        .move_by_offset(-10, 0)\
        .click_and_hold()\
        .move_by_offset(-1, 0)\
        .release()\
        .perform()
开发者ID:keisetsu,项目名称:wed,代码行数:13,代码来源:context_menu.py


示例12: on_placeholder

def on_placeholder(context):
    driver = context.driver
    util = context.util

    placeholder = util.find_element((By.CLASS_NAME, "_placeholder"))
    assert_true(util.visible_to_user(placeholder),
                "must be visible to the user; otherwise this step "
                "is not something the user can do")
    ActionChains(driver) \
        .context_click(placeholder) \
        .perform()
    context.context_menu_trigger = Trigger(util, placeholder)
    context.context_menu_for = placeholder
开发者ID:bennettbuchanan,项目名称:wed,代码行数:13,代码来源:context_menu.py


示例13: context_choices_insert

def context_choices_insert(context, kind):
    util = context.util

    cm = util.find_element((By.CLASS_NAME, "wed-context-menu"))

    search_for = None
    if kind == "inserting new elements":
        search_for = "Create new "
    elif kind == "wrapping text in new elements":
        search_for = "Wrap in "
    else:
        raise ValueError("can't search for choices of this kind: " + kind)

    cm.find_element(By.PARTIAL_LINK_TEXT, search_for)
开发者ID:keisetsu,项目名称:wed,代码行数:14,代码来源:context_menu.py


示例14: context_menu_appears

def context_menu_appears(context):
    util = context.util

    util.find_element((By.CLASS_NAME, "wed-context-menu"))
开发者ID:keisetsu,项目名称:wed,代码行数:4,代码来源:context_menu.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python selenium.selenium函数代码示例发布时间:2022-05-27
下一篇:
Python selectors.DefaultSelector类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap