Skip to content

Commit 5404831

Browse files
author
WKH
committed
delete workspace.xml
2 parents 937b739 + c44a777 commit 5404831

File tree

3 files changed

+71
-45
lines changed

3 files changed

+71
-45
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ python案例分享
55
案例二:python unittest使用<br>
66
案例三:python selenium使用<br>
77
案例四:unittest_selenium使用<br>
8+
案例五:python selenium递归<br>
9+
10+
811

readFile.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from time import sleep
2+
from selenium import webdriver
3+
4+
def getFile(url):
5+
#实例化一个浏览器驱动
6+
chrome = webdriver.Chrome()
7+
8+
#访问页面
9+
chrome.get(url)
10+
#捕获元素
11+
12+
texts = chrome.find_elements_by_xpath("//div[@class='content']/p")
13+
for t in texts:
14+
print(t.text)
15+
sleep(1)
16+
next_url = chrome.find_elements_by_xpath("//a[@class='nextchapter']")
17+
if next_url:
18+
next_urls = next_url[0].get_attribute("href")
19+
getFile(next_urls)
20+
else:
21+
chrome.close()
22+
return
23+
#关闭浏览器

unittest_selenium使用.py

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -73,48 +73,48 @@
7373
# if __name__ == '__main__':
7474
# unittest.main()
7575

76-
77-
import unittest
78-
from time import sleep
79-
from selenium import webdriver
80-
from HTMLTestRunner import HTMLTestRunner
81-
82-
class YouJiuyeTest(unittest.TestCase):
83-
def setUp(self):
84-
self.chrome = webdriver.Chrome()
85-
self.chrome.get("http://xue.ujiuye.com/foreuser/login/")
86-
87-
def login(self,username,pasword):
88-
username_d1 = self.chrome.find_element_by_id("username_dl")
89-
password_dl = self.chrome.find_element_by_id("password_dl")
90-
button = self.chrome.find_elements_by_class_name("loginbutton1")
91-
username_d1.send_keys(username)
92-
password_dl.send_keys(pasword)
93-
button[0].click()
94-
text = self.chrome.find_element_by_id("J_usernameTip").text
95-
return text
96-
97-
def test_login_password(self):
98-
text = self.login("13331153361","123")
99-
self.assertEqual("密码应该为6-20位之间!",text,"密码太短提示内容有误")
100-
101-
def test_login_username(self):
102-
text = self.login("13331153361","12345678")
103-
self.assertEqual("账号不存在", text, "提示内容有误")
104-
105-
def tearDown(self):
106-
sleep(10)
107-
self.chrome.close()
108-
109-
if __name__ == '__main__':
110-
suite = unittest.TestSuite()
111-
suite.addTest(YouJiuyeTest("test_login_password"))
112-
suite.addTest(YouJiuyeTest("test_login_username"))
113-
114-
with open("report.html","wb") as f:
115-
runner = HTMLTestRunner(
116-
stream=f,
117-
title="教学测试",
118-
description="就是一个教学测试"
119-
)
120-
runner.run(suite)
76+
#
77+
# import unittest
78+
# from time import sleep
79+
# from selenium import webdriver
80+
# from HTMLTestRunner import HTMLTestRunner
81+
#
82+
# class YouJiuyeTest(unittest.TestCase):
83+
# def setUp(self):
84+
# self.chrome = webdriver.Chrome()
85+
# self.chrome.get("http://xue.ujiuye.com/foreuser/login/")
86+
#
87+
# def login(self,username,pasword):
88+
# username_d1 = self.chrome.find_element_by_id("username_dl")
89+
# password_dl = self.chrome.find_element_by_id("password_dl")
90+
# button = self.chrome.find_elements_by_class_name("loginbutton1")
91+
# username_d1.send_keys(username)
92+
# password_dl.send_keys(pasword)
93+
# button[0].click()
94+
# text = self.chrome.find_element_by_id("J_usernameTip").text
95+
# return text
96+
#
97+
# def test_login_password(self):
98+
# text = self.login("13331153361","123")
99+
# self.assertEqual("密码应该为6-20位之间!",text,"密码太短提示内容有误")
100+
#
101+
# def test_login_username(self):
102+
# text = self.login("13331153361","12345678")
103+
# self.assertEqual("账号不存在", text, "提示内容有误")
104+
#
105+
# def tearDown(self):
106+
# sleep(10)
107+
# self.chrome.close()
108+
#
109+
# if __name__ == '__main__':
110+
# suite = unittest.TestSuite()
111+
# suite.addTest(YouJiuyeTest("test_login_password"))
112+
# suite.addTest(YouJiuyeTest("test_login_username"))
113+
#
114+
# with open("report.html","wb") as f:
115+
# runner = HTMLTestRunner(
116+
# stream=f,
117+
# title="教学测试",
118+
# description="就是一个教学测试"
119+
# )
120+
# runner.run(suite)

0 commit comments

Comments
 (0)