├── all_tests.py
├── allcase_list.py
├── data
├── TheAssertion
└── __init__.py
├── html
├── __init__.py
├── frame.html
├── inner.html
└── objects.html
├── image
└── __init__.py
├── package
├── __init__.py
├── __init__.pyc
├── common.py
├── common.pyc
├── resource.py
├── resource.pyc
├── user_info.py
└── user_info.pyc
├── readme
├── report
├── 2014-11-09-16_16_09allTests.html
└── __init__.py
├── selenium2
├── __init__.py
└── seleniumAPI.py
└── test_case
├── Assertions.py
├── Assertions.pyc
├── __init__.py
├── __init__.pyc
├── baidu.py
├── baidu.pyc
├── sina.py
└── sina.pyc
/all_tests.py:
--------------------------------------------------------------------------------
1 | #!-*- coding:utf-8 -*-
2 |
3 | #使用相对路劲把test目录添加到path下
4 | import sys
5 | import unittest
6 | import HTMLTestRunner
7 | import time
8 | import allcase_list
9 |
10 |
11 | #创建测试容器
12 | testunit=unittest.TestSuite()
13 |
14 |
15 | #获取数组文件
16 | alltestnames=allcase_list.caselist()
17 |
18 | #循环读取数组中的用例
19 | for db in alltestnames:
20 | testunit.addTest(unittest.makeSuite(db))
21 |
22 |
23 | #获取现在的时间
24 | now=time.strftime("%Y-%m-%d-%H_%M_%S",time.localtime(time.time()))
25 | #定义报告存放路劲
26 | filename='D:\\Git\\PyCharm\\Develop-Python-Selenium2\\report\\'+now+'allTests.html'
27 | fp=file(filename,'wb')
28 |
29 | #定义测试报告
30 | runner=HTMLTestRunner.HTMLTestRunner(
31 | #报告写入的文件
32 | stream=fp,
33 | #报告标题
34 | title=u'引入测试套件执行测试集执行用例',
35 | #报告的说明与描述
36 | description=u'用例执行情况')
37 | # #执行测试套件
38 | # runner=unittest.TextTestRunner()
39 | # runner.run(testunit)
40 |
41 | #执行用例
42 | runner.run(testunit)
43 |
44 |
45 |
--------------------------------------------------------------------------------
/allcase_list.py:
--------------------------------------------------------------------------------
1 | #!-*- coding:utf-8 -*-
2 | '''
3 | 作者:无涯
4 | 方法描述:用例集设置成数组的形式读取
5 | 完成时间:2014-09-08 20:55:21
6 | '''
7 | import sys
8 | sys.path.append("\test_case")
9 | from test_case import *
10 |
11 | #用例文件列表
12 | def caselist():
13 | alltestnames=[
14 | Assertions.Assertions,
15 | baidu.Baidu]
16 | print "success read case list!"
17 |
18 | return alltestnames
--------------------------------------------------------------------------------
/data/TheAssertion:
--------------------------------------------------------------------------------
1 | selenium提供了三种模式的断言:assert,verify,waitfor
2 | Assert:失败时,该测试将终止
3 | Verify:失败时,该测试继续执行,并将错误日志记录在日显示屏
4 | Waitfor:等待某些条件变为真,一般使用在AJAX应用程序的测试
5 |
6 |
7 | 断言常用的有,具体见如下:
8 | assertLocation:判断当前是在正确的页面
9 | assertTitle:检查当前页面的title是否正确
10 | assertValue:检查input的值,check or radio,有为on,无为off
11 | assertSelected:检查select的下拉菜单中选中是否正确
12 | assertSelectedOptions:检查下拉菜单中的A选项是否正确
13 | asserttext:检查指定元素的文本
14 | assertTextParset:检查在当前给用户显示的页面上是否具有出现指定的文本
15 | asserttextNotPresent:检查在当前给用户显示的页面上是否没有出现指定的文本
16 | assertAttribute:检查当前指定元素的属性的值
17 | assertTable:检查table里的某个cell中的值
18 | assertEditable:检查指定的input是否可以编辑
19 | assertNotEditable:检查指定的input是否不可以编辑
20 | assertAlert:检查是否有产生带指定message的alert对话框
21 | verifyTitle:验证预期的页面标题
22 | verifyTextPresent:验证预期的文本是否在页面上的某个位置
23 | verifyElementPresent:验证预期的UI元素,它的html标签的定义,是否在当前网页上
24 | verifyText:核实预期的文本和相应的HTML标签是否都存在于页面上
25 | verifyTable:验证表的预期内容
26 | waitForPageToLoad:暂停执行,直到预期的新的页面加载
27 | waitForElementPresent:等待检验某元素的存在,为真时,则执行
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/data/__init__.py:
--------------------------------------------------------------------------------
1 | __author__ = 'Administrator'
2 |
--------------------------------------------------------------------------------
/html/__init__.py:
--------------------------------------------------------------------------------
1 | __author__ = 'Administrator'
2 |
--------------------------------------------------------------------------------
/html/frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | frame
5 |
7 |
9 |
12 |
13 |
14 |
15 |
16 |
frame
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/html/inner.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | inner
5 |
6 |
7 |
8 |
9 |
inner
10 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/html/objects.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Checkbox
5 |
7 |
9 |
10 |
11 |
12 | checkbox
13 |
35 |
36 |
--------------------------------------------------------------------------------
/image/__init__.py:
--------------------------------------------------------------------------------
1 | __author__ = 'Administrator'
2 |
--------------------------------------------------------------------------------
/package/__init__.py:
--------------------------------------------------------------------------------
1 | #!-*- coding:utf-8 -*-
2 | import sys
3 | reload(sys)
4 | sys.setdefaultencoding('utf-8')
5 | sys.path.append("\package")
6 | import common
7 | import resource
8 | import user_info
9 |
10 |
11 |
--------------------------------------------------------------------------------
/package/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huahuijay/python-selenium2/d9fe7d5e8b1706ec252b4320c5eadac7d021c290/package/__init__.pyc
--------------------------------------------------------------------------------
/package/common.py:
--------------------------------------------------------------------------------
1 | #!-*- coding:utf-8 -*-
2 | import sys
3 | reload(sys)
4 | sys.setdefaultencoding('utf-8')
5 |
6 | '''
7 | 1、webdriver的二次封装
8 | 2、采用page object设计模式,简化代码
9 | '''
10 |
11 | from selenium import webdriver
12 |
13 |
14 |
15 | '''定位单个元素封装'''
16 | def findID(driver,id):
17 | f=driver.find_element_by_id(id)
18 | return f
19 |
20 | def findName(driver,name):
21 | f=driver.find_element_by_name(name)
22 | return f
23 |
24 | def findClassName(driver,name):
25 | f=driver.find_element_by_class_name(name)
26 | return f
27 |
28 | def findTagName(driver,name):
29 | f=driver.find_element_by_tag_name(name)
30 | return f
31 |
32 | def findLinkText(driver,text):
33 | f=driver.find_element_by_link_text(text)
34 | return f
35 |
36 | def findPLinkText(driver,text):
37 | f=driver.find_element_by_partial_link_text(text)
38 | return f
39 |
40 | def findXpath(driver,xpath):
41 | f=driver.find_element_by_xpath(xpath)
42 | return f
43 |
44 | def findCss(driver,css):
45 | f=driver.find_element_by_css_selector(css)
46 | return f
47 |
48 | '''定位一组元素封装'''
49 | def findsID(driver,id):
50 | f=driver.find_elements_by_id(id)
51 | return f
52 |
53 | def findsName(driver,name):
54 | f=driver.find_elements_by_name(name)
55 | return f
56 |
57 | def findsClassName(driver,name):
58 | f=driver.find_elements_by_class_name(name)
59 | return f
60 |
61 | def findTagName(driver,name):
62 | f=driver.find_element_by_tag_name(name)
63 | return f
64 |
65 | def findsLinkText(driver,text):
66 | f=driver.find_elements_by_link_text(text)
67 | return f
68 |
69 | def findsPLinkText(driver,text):
70 | f=driver.find_elements_by_partial_link_text(text)
71 | return f
72 |
73 | def findsXpath(driver,xpath):
74 | f=driver.find_elements_by_xpath(xpath)
75 | return f
76 |
77 | def findsCss(driver,css):
78 | f=driver.find_elements_by_css_selector(css)
79 | return f
80 |
--------------------------------------------------------------------------------
/package/common.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huahuijay/python-selenium2/d9fe7d5e8b1706ec252b4320c5eadac7d021c290/package/common.pyc
--------------------------------------------------------------------------------
/package/resource.py:
--------------------------------------------------------------------------------
1 | #!-*- coding:utf-8 -*-
2 | import sys
3 | reload(sys)
4 | sys.setdefaultencoding('utf-8')
5 | '''系统所有的提示信息'''
6 | inputName=u'请输入用户名'
7 |
--------------------------------------------------------------------------------
/package/resource.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huahuijay/python-selenium2/d9fe7d5e8b1706ec252b4320c5eadac7d021c290/package/resource.pyc
--------------------------------------------------------------------------------
/package/user_info.py:
--------------------------------------------------------------------------------
1 | #!-*- coding:utf-8 -*-
2 | import sys
3 | reload(sys)
4 | sys.setdefaultencoding('utf-8')
5 |
6 | #百度搜索输入的ID
7 | soID='kw'
8 | #百度一下的id
9 | clickID='su'
--------------------------------------------------------------------------------
/package/user_info.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huahuijay/python-selenium2/d9fe7d5e8b1706ec252b4320c5eadac7d021c290/package/user_info.pyc
--------------------------------------------------------------------------------
/readme:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huahuijay/python-selenium2/d9fe7d5e8b1706ec252b4320c5eadac7d021c290/readme
--------------------------------------------------------------------------------
/report/2014-11-09-16_16_09allTests.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 引入测试套件执行测试集执行用例
6 |
7 |
8 |
9 |
92 |
93 |
94 |
95 |
189 |
190 |
191 |
引入测试套件执行测试集执行用例
192 |
Start Time: 2014-11-09 16:16:09
193 |
Duration: 0:02:40.622000
194 |
Status: Pass 7
195 |
196 |
用例执行情况
197 |
198 |
199 |
200 |
201 | Show
202 | Summary
203 | Failed
204 | All
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
223 |
224 |
225 | test_case.Assertions.Assertions |
226 | 2 |
227 | 2 |
228 | 0 |
229 | 0 |
230 | Detail |
231 |
232 |
233 |
234 | testAssertion: 断言的测试 |
235 | pass |
236 |
237 |
238 |
239 | testImage: 错误截图的获取 |
240 | pass |
241 |
242 |
243 |
244 | test_case.baidu.Baidu |
245 | 5 |
246 | 5 |
247 | 0 |
248 | 0 |
249 | Detail |
250 |
251 |
252 |
253 | testBaidu: 百度测试 |
254 | pass |
255 |
256 |
257 |
258 | testClick |
259 | pass |
260 |
261 |
262 |
263 | testInputName |
264 |
265 |
266 |
267 |
269 |
270 |
282 |
283 |
284 | |
285 |
286 |
287 |
288 | testUser_Info |
289 | pass |
290 |
291 |
292 |
293 | testVke |
294 | pass |
295 |
296 |
297 |
298 | Total |
299 | 7 |
300 | 7 |
301 | 0 |
302 | 0 |
303 | |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
--------------------------------------------------------------------------------
/report/__init__.py:
--------------------------------------------------------------------------------
1 | __author__ = 'Administrator'
2 |
--------------------------------------------------------------------------------
/selenium2/__init__.py:
--------------------------------------------------------------------------------
1 | __author__ = 'Administrator'
2 |
--------------------------------------------------------------------------------
/selenium2/seleniumAPI.py:
--------------------------------------------------------------------------------
1 | #!-*- coding:utf-8 -*-
2 | '''
3 | Created on 2014-11-16
4 | @description:selenium2 webdriver API code
5 | @author: Administrator
6 | '''
7 | import sys
8 | reload(sys)
9 | sys.setdefaultencoding('utf-8')
10 |
11 | from selenium2 import webdriver
12 | from selenium2.webdriver.common.keys import Keys
13 | from selenium2.webdriver.support.ui import Select
14 | from selenium2.common.exceptions import NoSuchElementException
15 | from selenium2.webdriver.common.by import By
16 | import unittest,time,re,os,time
17 |
18 | #导入公共的类
19 | from package import common
20 |
21 | class Baidu(unittest.TestCase):
22 | def setUp(self):
23 | self.driver=webdriver.Firefox()
24 | self.driver.implicitly_wait(30)
25 | self.driver.maximize_window()
26 | self.base_url=''
27 | self.verificationErrors=[]
28 | self.accept_next_alert=True
29 |
30 |
31 | def tearDown(self):
32 | driver=self.driver
33 | driver.close()
34 | self.assertEqual([],self.verificationErrors)
35 |
36 | if __name__=='__main__':
37 | unittest.main()
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/test_case/Assertions.py:
--------------------------------------------------------------------------------
1 | #!-*- coding:utf-8 -*-
2 | import unittest
3 | import sys
4 | reload(sys)
5 | sys.setdefaultencoding('utf-8')
6 | '''断言的测试应用'''
7 | from selenium import webdriver
8 | class Assertions(unittest.TestCase):
9 | def setUp(self):
10 | self.driver=webdriver.Firefox()
11 | self.driver.implicitly_wait(30)
12 | self.driver.maximize_window()
13 | self.base_url='http://www.baidu.com'
14 | #脚本运行时,错误的信息将打印到这个列表中
15 | self.verificationErrors=[]
16 | #是否接受下一个A警告
17 | self.accept_next_alert=True
18 |
19 | def testAssertion(self):
20 | '''断言的测试'''
21 | driver=self.driver
22 | driver.get(self.base_url+'/')
23 | #断言来判断title是否正确
24 | try:
25 | self.assertEqual(u'百度一下,你就知道',driver.title)
26 | except AssertionError as e:
27 | self.verificationErrors.append(str(e))
28 |
29 | '''测试错误的截图'''
30 | def testImage(self):
31 | '''错误截图的获取'''
32 | driver=self.driver
33 | driver.get('http://www.baidu.com')
34 | try:
35 | driver.find_element_by_id('kw1ffg').send_keys('webdriver')
36 | except:
37 | driver.get_screenshot_as_file('D:/Git/PyCharm/pythonSelenium2/image/error_png.png')
38 |
39 |
40 | def tearDown(self):
41 | driver=self.driver
42 | driver.close()
43 | self.assertEqual([],self.verificationErrors)
44 |
45 | if __name__=='__main__':
46 | #创建测试容器
47 | suite=unittest.TestSuite()
48 | #添加测试用例
49 | suite.addTest(Assertions('testAssertion'))
50 | #suite.addTest(Assertions('testImage'))
51 | #unittest.makeSuite(Assertions,'test_case')
52 | #执行测试用例
53 | runner=unittest.TextTestRunner()
54 | #执行用例
55 | runner.run(suite)
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/test_case/Assertions.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huahuijay/python-selenium2/d9fe7d5e8b1706ec252b4320c5eadac7d021c290/test_case/Assertions.pyc
--------------------------------------------------------------------------------
/test_case/__init__.py:
--------------------------------------------------------------------------------
1 | #!-*- coding:utf-8 -*-
2 | import sys
3 | reload(sys)
4 | sys.setdefaultencoding('utf-8')
5 | '''把test_case目录添加到path下,这里使用的是相对路劲'''
6 | sys.path.append("\test_case")
7 | from test_case import Assertions
8 | from test_case import baidu
9 | from package import common
10 |
11 | #导入测试文件
12 | import baidu ,Assertions
13 |
--------------------------------------------------------------------------------
/test_case/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huahuijay/python-selenium2/d9fe7d5e8b1706ec252b4320c5eadac7d021c290/test_case/__init__.pyc
--------------------------------------------------------------------------------
/test_case/baidu.py:
--------------------------------------------------------------------------------
1 | #!-*- coding:utf-8 -*-
2 | import sys
3 | reload(sys)
4 | sys.setdefaultencoding('utf-8')
5 |
6 | from selenium import webdriver
7 | from selenium.webdriver.common.keys import Keys
8 | from selenium.webdriver.support.ui import Select
9 | from selenium.common.exceptions import NoSuchElementException
10 | from selenium.webdriver.common.by import By
11 | import unittest,time,re,os,time
12 | #引入HTMLTestRunner包
13 | import HTMLTestRunner
14 | import baidu
15 |
16 | #导入公共的类
17 | from package import common
18 | from package import user_info
19 | from package import resource
20 |
21 |
22 | class Baidu(unittest.TestCase):
23 | def setUp(self):
24 | self.driver=webdriver.Firefox()
25 | self.driver.implicitly_wait(30)
26 | self.driver.maximize_window()
27 | self.base_url='http://www.baidu.com'
28 | #脚本运行时,错误的信息将打印到这个列表中
29 | self.verificationErrors=[]
30 | #是否接受下一个A警告
31 | self.accept_next_alert=True
32 |
33 | def testBaidu(self):
34 | '''百度测试'''
35 | driver=self.driver
36 | driver.get(self.base_url+'/')
37 | #断言来判断title是否正确
38 | try:
39 | self.assertEqual(u'百度一下,你就知道',driver.title)
40 | except AssertionError as e:
41 | self.verificationErrors.append(str(e))
42 |
43 | def testVke(self):
44 | driver=self.driver
45 | driver.get('http://www.baidu.com')
46 | common.findID(driver,'kw').send_keys('webdriver')
47 |
48 | def testClick(self):
49 | driver=self.driver
50 | driver.get('http://www.baidu.com')
51 | common.findID(driver,'kw').send_keys('webdriver')
52 | common.findID(driver,'su').click()
53 |
54 | def testUser_Info(self):
55 | driver=self.driver
56 | driver.get('http://www.baidu.com')
57 | common.findID(driver,user_info.soID).send_keys('webdriver')
58 | common.findID(driver,user_info.clickID).click()
59 | time.sleep(3)
60 |
61 | def testInputName(self):
62 | driver=self.driver
63 | driver.get('http://my.weke.com/login.html')
64 | driver.find_element_by_class_name('login-btn').click()
65 | text=driver.find_element_by_xpath('html/body/div[1]/div[2]/div[2]/div/div[2]').text
66 | if text==resource.inputName:
67 | print '测试通过'
68 | else:
69 | print '提示信息错误,请提单跟踪!'
70 |
71 |
72 |
73 |
74 | def tearDown(self):
75 | driver=self.driver
76 | driver.close()
77 | self.assertEqual([],self.verificationErrors)
78 |
79 | if __name__=='__main__':
80 | suite=unittest.TestSuite()
81 | #suite.addTest(Baidu('testBaidu'))
82 | suite.addTest(unittest.makeSuite(baidu.Baidu))
83 |
84 | #定义报告存放路劲
85 | filename="D:\\Git\\PyCharm\\pythonSelenium2\\report\\result.html"
86 | fp=file(filename,'wb')
87 | runner=HTMLTestRunner.HTMLTestRunner(
88 | stream=fp,
89 | title=u'百度测试报告',
90 | description=u'用例执行情况:'
91 | )
92 | runner.run(suite)
93 | #关闭报告文件
94 | fp.close()
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/test_case/baidu.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huahuijay/python-selenium2/d9fe7d5e8b1706ec252b4320c5eadac7d021c290/test_case/baidu.pyc
--------------------------------------------------------------------------------
/test_case/sina.py:
--------------------------------------------------------------------------------
1 | #!-*- coding:utf-8 -*-
2 | import unittest
3 | import time
4 | import sys
5 | import os
6 | reload(sys)
7 | sys.setdefaultencoding('utf-8')
8 | '''断言的测试应用'''
9 | from selenium import webdriver
10 | #鼠标事件
11 | from selenium.webdriver.common.action_chains import ActionChains
12 | #键盘事件
13 | from selenium.webdriver.common.keys import Keys
14 | #超时等待
15 | from selenium.webdriver.support.ui import WebDriverWait
16 |
17 | #引用封装的类
18 | from package import *
19 | class Assertions(unittest.TestCase):
20 | def setUp(self):
21 | self.driver=webdriver.Firefox()
22 | self.driver.implicitly_wait(30)
23 | self.driver.maximize_window()
24 | self.base_url='http://www.baidu.com'
25 | self.verificationErrors=[]
26 | self.accept_next_alert=True
27 |
28 | def testSina(self):
29 | driver=self.driver
30 | driver.get(self.base_url)
31 | common.findCss(driver,".tn-tab>i").click()
32 |
33 | #操作测试对象
34 | def testObject(self):
35 | driver=self.driver
36 | driver.get(self.base_url)
37 | #在新浪搜索输入框作为测试的对象
38 | so=common.findID(driver,'kw')
39 | so.clear()
40 | so.send_keys(u'sina测试')
41 | common.findID(driver,'su').submit()
42 | testText=common.findClassName(driver,'toindex').text
43 | try:
44 | self.assertEqual(u'百度首页',testText)
45 | except AssertionError as e:
46 | self.verificationErrors.append(str(e))
47 |
48 | def testProperty(self):
49 | driver=self.driver
50 | driver.get(self.base_url)
51 | #百度搜索输入框的属性值
52 | attributeText=common.findID(driver,'kw').get_attribute('type')
53 | print attributeText
54 | #利用元素的属性测试百度搜索设置
55 | def testSoSet(self):
56 | driver=self.driver
57 | driver.get(self.base_url)
58 | common.findLinkText(driver,u'设置').click()
59 | common.findLinkText(driver,u'搜索设置').click()
60 | options=driver.find_elements_by_tag_name('option')
61 | value=u'100'
62 | for option in options:
63 | if option.get_attribute('value')==value:
64 | option.click()
65 | time.sleep(5)
66 |
67 | #判断是否可见
68 | def test_isDisplayed(self):
69 | driver=self.driver
70 | driver.get(self.base_url)
71 | result=common.findName(driver,'tj_trmap').is_displayed()
72 | try:
73 | self.assertEqual(True,result)
74 | except AssertionError as e:
75 | self.verificationErrors.append(str(e))
76 |
77 | #鼠标事件
78 | #已百度首页的更多产品,鼠标停留在为实例
79 | def testAction(self):
80 | driver=self.driver
81 | driver.get(self.base_url)
82 | above=common.findLinkText(driver,u'更多产品')
83 | ActionChains(driver).move_to_element(above).perform()
84 | time.sleep(5)
85 |
86 | def testKeys(self):
87 | '''键盘事件'''
88 | driver=self.driver
89 | driver.get(self.base_url)
90 | so=common.findID(driver,'kw')
91 | so.send_keys('webdriver')
92 | so.send_keys(Keys.CONTROL,'a')
93 | so.send_keys(Keys.DELETE)
94 | time.sleep(3)
95 | so.send_keys(Keys.F5)
96 | time.sleep(3)
97 |
98 | def testWait(self):
99 | '''设置等待时间'''
100 | driver=self.driver
101 | driver.get(self.base_url)
102 | so=WebDriverWait(driver, 10).until(lambda driver :common.findID(driver,'kw'))
103 | so.send_keys('webdriver')
104 | time.sleep(3)
105 |
106 | def testGroup(self):
107 | '''定位一组对象'''
108 | driver=self.driver
109 | #先已标记对定位到所有的元素,然后依据属性过滤出,点击勾选
110 | file_path=os.path.abspath("D:\\Git\\PyCharm\\Develop-Python-Selenium2\\html\\objects.html")
111 | driver.get(file_path)
112 | inputs=driver.find_elements_by_tag_name('input')
113 | for input in inputs:
114 | if input.get_attribute('type')=='checkbox':
115 | input.click()
116 | time.sleep(5)
117 |
118 | def testFrame(self):
119 | driver=self.driver
120 | file=os.path.abspath("D:\\Git\\PyCharm\\Develop-Python-Selenium2\\html\\frame.html")
121 | driver.get(file)
122 | #先寻找到frame1,再依次寻找frame2
123 | driver.switch_to_frame('f1')
124 | driver.switch_to_frame('f2')
125 | #对frame2中的属性进行操作
126 | common.findID(driver,'kw').send_keys('kw')
127 | time.sleep(4)
128 |
129 |
130 |
131 | def tearDown(self):
132 | driver=self.driver
133 | driver.quit()
134 | self.assertEqual([],self.verificationErrors)
135 |
136 | if __name__=='__main__':
137 | unittest.main()
138 |
139 |
140 |
141 |
142 |
--------------------------------------------------------------------------------
/test_case/sina.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huahuijay/python-selenium2/d9fe7d5e8b1706ec252b4320c5eadac7d021c290/test_case/sina.pyc
--------------------------------------------------------------------------------