zoukankan      html  css  js  c++  java
  • selenium定位元素

    1.通过id定位:

    HTML规定id属性在HTML文档中必须是唯一的,类似于身份证具有很强的唯一性,通过元素的id属性查找元素,用法如下(百度为例):

    find_element_by_id(“kw)

    find_element_by_id("su")

    2.通过name定位:

    HTML规定通过name来指定元素的名称,类似于人的姓名,可以在当前页面不唯一,通过元素的name属性查找元素,用法如下(百度为例):

    find_element_by_name("wd")

    3.通过class定位:

    HTML规定通过class来指定元素的类名,用法和id,name一样,下面通过class来定位百度输入框和搜索框

    find_element_by_class_name("spit")

    4.通过tag定位:

    HTML的本质是通过tag来定义实现不同的功能,每个元素本质上也是一个tag,例如<div>,<input>等,,用法如下(百度为例):

    find_element_by_tag_name("input")

    5.通过link定位:

    link定位专门用来定位文本链接,使用方法如下:

    <a href="https://voice.baidu.com/act/newpneumonia/newpneumonia/?from=osari_pc_1" target="_blank" id="virus-2020" class="s-top-right-text c-font-normal c-color-red dot">抗击肺炎</a>

    find_element_by_link_text("抗击肺炎“)

    6.通过partial link定位:

    partial link是link定位的补充,有些文本链接较长,就可以取一部分

    <a href="https://voice.baidu.com/act/newpneumonia/newpneumonia/?from=osari_pc_1" target="_blank" id="virus-2020" class="s-top-right-text c-font-normal c-color-red dot">抗撒大大大苏打大大击肺炎</a>

    find_element_by_partial_link_text("肺炎")

  • 相关阅读:
    精确覆盖DLX算法模板另一种写法
    Hdu3498-whosyourdaddy(精确覆盖模板题)
    精确覆盖DLX算法模板
    Object2Map
    Use ResourceBundle read properties file.
    Kendo UI Example(grid)
    Kendo 日期控件
    Spring mvc 中文乱码问题解决方法
    Thread communication java.util.concurrent.locks.Condition 用法(二)
    Thread communication java.util.concurrent.locks.Condition 用法(一)
  • 原文地址:https://www.cnblogs.com/zhifeiji822/p/13039090.html
Copyright © 2011-2022 走看看