selenium2+Python3的基本定位操作
一、通过id定位元素
使用:driver.find_element_by_id('id_value')
当id是静态元素且唯一的时候,使用id定位是最方便的。
注意点:当有些id值是动态变化的,则不能使用该方法定位


二、通过name定位元素
使用:driver.find_element_by_name('name_value')
跟id定位元素类似,使用起来非常方便


三、通过class_name定位元素
用法:driver.find_element_by_class_name('class_name_value')
跟那么name定位元素类似
注意点:不过,当class_name元素重复时,就不能使用此方法了。一般class_name用于定位复式元素。


四、通过tag_name定位元素
用法:driver.find_element_by_tag_name('tag_name_value')
tag_name常用于定位复选框。平常定位时,不建议使用tag_name

五、通过link_text定位元素
用法:driver.find_element_by_link_text('精确文字')
通过精确文字定位元素(跟精确搜索类似)


六、通过partial_link_text定位元素
用法:driver.find_element_by_partial_link_text('模糊文字')
通过模糊文字进行元素定位(跟模糊搜索类似)


七、通过css_selector定位元素
用法:driver.find_element_by_css_selector('css')

1.通过id定位元素
# 代表通过id的值来定位元素

2.通过class定位元素
. 代表通过class的值来定位元素,一般和标签一起使用

3.通过属性值来定位元素

4.节点混合定位
用法:driver.find_element_by_css_selector('父标签>子标签')

八、通过xpath定位元素
* 代表所有元素
绝对路径:以/开头的,是从根节点html开始寻找的
相对路径:以//开头的,是从所有节点去寻找元素