2018-09-06-零基础入门python_selenium自
本小序除开本句和下句,都是干货
1、自动化测试流程

2、OpenBrowser详解
OpenBrowser:打开浏览器
封装成函数,在文件最上面导入包:from seleniumimport webdriver

3、OpenUrl详解
OpenUrl:打开网址,使用浏览器的get方法

4、findElement详解
findElement:元素定位,元素定位的8种方法:
(1)find_element_by_id()


(2)find_element_by_link_text()


find_element_by_partial_link_text()表示按照上述的text的一部分,例如,‘新’或者‘闻’
(3)find_element_by_name()
说明:运行后会报错,说明这个搜索框的name属性不是唯一的,无法通过name属性直接定位到输入框

(4)find_element_by_class_name()


(5)find_element_by_tag_name()
从上面定位到的元素属性中,可以看到每个元素都有tag(标签)属性,如搜索框的标签属性,就是最前面的input,但是在一个页面中,相同的标签有很多,所以一般不用标签来定位


(6)find_element_by_xpath()
以上定位方式都是通过元素的某个属性来定位的,如果一个元素它既没有id、name、class属性也不是超链接,这么办呢?或者说它的属性很多重复的。这个时候就可以用xpath解决:以google为例:右键鼠标


(7)find_element_by_css_selector()
ss是另外一种语法,比xpath更为简洁,但是不太好理解


定位元素详解:
1.通过id定位:find_element_by_id()
2.通过name定位:find_element_by_name()
3.通过class定位:find_element_by_class_name()
4.通过tag定位:find_element_by_tag_name()
5.通过link定位:find_element_by_link_text()
6.通过partial_link定位:find_element_by_partial_link_text()
7.通过xpath定位:find_element_by_xpath()
8.通过css定位:find_element_by_css_selector()
本例中所有的查看程序为:

4、sendkeys详解
通常,selenium中,使用send_keys方法传输值

5、checkResult
首先介绍一下WebDriverWait()函数,通常使用方式为WebDriverWait(driver,times).until(func)或者是WebDriverWait(driver,times).until(func),.until():表示在times时间内,如果func没有成功执行则失败,.until_not()表示在times时间内,如果func成功执行则失败
定义该函数:

定义检查函数

以上就是ui自动化测试的整个步骤,可作为简单了解