has been studying scrapy data capture, in the study of Ajax data capture happened to study the selenium, is really practical, but only to do scrapy under the data crawl, not suitable, one is the loss of performance, has to open a browser, and the second is for the crawler, Analyzing AJAX Requests is a matter of fact. All right, that's far. I've got some ideas for automated testing today.
There are many automated test libraries under Python, selenium is the big kill device for browser testing, about selenium:
refer:http://www.seleniumhq.org/
Some additional guidance on installation and the Python environment I will not list, a large online:)
When testing the Web site, often encountered some need to verify the code input, this time input parsing verification code, generally have the following several ways:
1. Submit to the Program logic processing:
The picture is download down to do verification code identification, and then fill in the Verification Code box, so that requires a special code identification block, a slightly larger number of codes
2. Temporarily comment out the identification code function of the Verification code
This eliminates the validation step
3. Write Dead Verification code function
So that the verification code identification can be arbitrarily tested.
In fact, the above three kinds of possibilities, nothing to see their own and programmers how to communicate and their technical level, if you want to practice practiced hand, you can do a verification code identification function out, if and developers communicate such as smooth, you can ask them temporarily comment or write a temporary verification code
Fourth, we can continue to operate in Python's open selenium browser, following the code directly:
123456789101112131415161718192021222324252627282930313233343536 |
#coding=utf-8
from
splinter
import
Browser
import
time
import
sys
reload
(sys)
sys.setdefaultencoding(
‘utf8‘
)
def
log_in_doban(Name
=
‘
‘, PassWrod = ‘
‘):
if
Name
and PassWrod:
bs
=
Browser(
‘chrome‘
)
bs.visit(url
=
‘http://www.douban.com/accounts/login?source=main‘
)
if bs.is_element_present_by_id(
id
=
‘email‘
):
bs.find_by_id(
id
=
‘email‘
).fill(Name)
bs.find_by_id(
id
=
‘password‘
).fill(PassWrod)
if
bs.is_element_present_by_id(
id
=
‘captcha_field‘
):
#bs.find_by_id(‘captcha_field‘).fill(code_img)
while
True
:
val
=
bs.find_by_id(
id
=
‘captcha_field‘
).first.value
if val
and
len
(val)>
0
:
bs.find_by_id(
‘captcha_field‘
).fill(val)
break
pass
pass
bs.find_by_name(
‘login‘
).click()
print
‘log in‘
#bs.quit()
if
__name__
=
=
‘__main__‘
:
log_in_doban(Name
=
‘test_account‘
,PassWrod
=
‘test_password‘
)
|
I feel that selenium can do a lot of things, since can be used to control the browser, then its implementation of the function will be many, such as brush tickets, such as Automatic post what, I do not introduce each.
Automated test--selenium Verification Code input problem under Python