码迷,mamicode.com
首页 > 其他好文 > 详细

简单对象定位

时间:2016-12-22 13:51:04      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:搜索   lin   hid   sub   partial   nbsp   python   input   属性   

简单对象定位:

webdriver 提供了一系列的元素定位方法,常用的有以下几种:

  • id
  • name
  • class name
  • tag name
  • link text
  • partial link text
  • xpath
  • css selector

分别对应python webdriver 中的方法为:

find_element_by_id()
find_element_by_name()
find_element_by_class_name()
find_element_by_tag_name()
find_element_by_link_text()
find_element_by_partial_link_text()
find_element_by_xpath()
find_element_by_css_selector()

1) id 和 name  定位:

id 和name 是我们最常用的定位方式,因为大多数元素都有这两个属性,而且在对控件的id 和name
命名时一般使其有意义也会取不同的名字。通过这两个属性使我们找一个页面上的属性变得相当容易。

html 代码:


<input id="gs_htif0" class="gsfi" aria-hidden="true" dir="ltr">
<input type="submit" name="btnK" jsaction="sf.chk" value="Google 搜索">
<input type="submit" name="btnI" jsaction="sf.lck" value=" 手气不错">


通过元素中所带的id 和name 属性对元素进行定位:

id=”gs_htif0”
find_element_by_id("gs_htif0")


name=”btnK”
find_element_by_name("btnK")

name=”btnI”
find_element_by_name("btnI")

简单对象定位

标签:搜索   lin   hid   sub   partial   nbsp   python   input   属性   

原文地址:http://www.cnblogs.com/jshtest/p/6210526.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!