Selenium automated Testing: How to use cookies to skip verification code login

Source: Internet
Author: User

For the general login site, there will be a verification code this thing, is generally for security considerations, in a security policy, this is a problem for us to do UI Automation testing, normal we can enter the user name, password to log in, if the popup verification code to deal with, It's a good choice to take a browser cookie.
Recommended Chrome plugin Editthiscookie, you can directly see the current site is using the cookie, for our login, we need to simulate the automatic login, there will generally be user information of the cookie exists inside, we do not need to take it all out, Just check with the development communication to be sure which one or those cookies are useful.

From selenium import Webdriver from time
import *
driver = webdriver. Chrome ()
driver.get ("https://xxxxxxxxxx")
sleep (6)
# Add Cookie
driver.add_cookie ({' name ': ' xxxx ', ' Value ': ' xxxxxxxxxxx '})

# Refresh page
Driver.refresh ()

#关闭浏览器
driver.quit ()

As shown in the above code, we need to open a URL, then add a cookie, and then refresh the page, if the cookie is correct, it will be able to achieve automatic login.

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.