selenium是一个用于web应用程序测试的工具,Selenium测试直接运行在浏览器中,就像真正的用户在操做同样。支持的浏览器包括IE、Mozilla Firefox、Mozilla Suite等。这个工具的主要功能包括:测试与浏览器的兼容性——测试你的应用程序看是否可以很好得工做在不一样浏览器和操做系统之上。测试系统功能——建立衰退测试检验软件功能和用户需求。支持自动录制动做和自动生成。Net、Java、Perl等不一样语言的测试脚本。Selenium 是ThoughtWorks专门为Web应用程序编写的一个验收测试工具。css
要使用selenium以前呢必须得先下载浏览器驱动器,我知道的浏览器只有这些html
最简单粗暴却失传已久的8种定位git
听说这种定位方式在江湖上都快要失传了,实在想不通为何,明明写起来最简单粗暴啊~github
driver.find_element("name","wd").send_keys("Selenium2")web
driver.find_element("id","su").click()chrome
你们必定会和我同样以为这种方式的定位实在是太省事了~只要写find_element就好啦,下面咱们来总结一下这8种写法与基本定位方法类比过来该怎么写:api
by_id -> find_element("id","")浏览器
by_xpath -> find_element("xpath","")工具
by_link_text -> find_element("link text","")测试
by_partial_text -> find_element("partial link text","")
by_name -> find_element("name","")
by_tag_name -> find_element("tag name","")
by_class_name -> find_element("class name","")
by_css_selector -> find_element("css selector","")
elements复数定位
在上面的例举的八中基本定位方式种,都有对应的复数形式,分别是下面这些:
id复数定位find_elements_by_id()
name复数定位find_elements_by_name()
class复数定位find_elements_by_class_name()
tag复数定位find_elements_by_tag_name()
link复数定位find_elements_by_link_text()
partial_link复数定位find_elements_by_partial_link_text()
xpath复数定位find_elements_by_xpath()
css复数定位find_elements_by_css_selector()
这些复数定位方式每次取到的都是具备相同类型属性的一组元素,因此返回的是一个list队列,咱们也能够利用这个去定位单个的元素。好比百度首页种,右上角有新闻、视频、地图、贴吧等一些连接,咱们经过f12查看源码能够发现,这些连接都有共同的class, class="mnav"。