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.