Automated test--selenium Verification Code input problem under Python

Source: Internet
Author: User

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-8fromsplinter importBrowserimporttimeimportsysreload(sys)sys.setdefaultencoding(‘utf8‘)deflog_in_doban(Name =‘, PassWrod = ‘‘):    ifName 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)            ifbs.is_element_present_by_id(id=‘captcha_field‘):                #bs.find_by_id(‘captcha_field‘).fill(code_img)                whileTrue:                    val =bs.find_by_id(id=‘captcha_field‘).first.value                    if val andlen(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.