#Encoding=utf-8ImportUnitTestImport Time fromSeleniumImportWebdriver fromSelenium.webdriverImportActionchainsclassVisitsogoubyie (unittest. TestCase):defsetUp (self):#Start IE browser #self.driver = Webdriver. Firefox (Executable_path = "E:\\geckodriver")Self.driver = Webdriver. Ie (Executable_path ="E:\\iedriverserver") defTest_cookie (self): URL="http://www.sogou.com" #Visit Sogou Homeself.driver.get (URL)#get all Cookies under the current page and output their domain, name, value, expiration, and pathcookies =self.driver.get_cookies () forCookiesinchCookies:Print " %s and%s,%s,%s" % (cookie['Domain'], cookie["name"], cookie["value"], cookie["expiry"], cookie["Path"]) #Obtain the cookie information based on the cookie's name value and obtain the cookie information with the name value of ' SUV 'CK = Self.driver.get_cookie ("SUV") Print " %s and%s,%s,%s" % (ck['Domain'], ck["name"], ck["value"], ck["expiry"], ck["Path"]) #There are 2 ways to delete cookies #First: Remove cookie information named "Abtest" with the Name property of the cookie PrintSelf.driver.delete_cookie ("abtest") #The second kind: Delete all cookie information at onceself.driver.delete_all_cookies ()#Once you have deleted all cookies, check the cookies again to confirm that they have been completely deleted .cookies =self.driver.get_cookies ()PrintCookies#Add custom cookie informationSelf.driver.add_cookie ({"name":"Gloryroadtrain",'value':'1479697159269020'}) #View the added cookie informationCookie = Self.driver.get_cookie ("Gloryroadtrain") PrintCookiesdefTearDown (self):#Exit IE Browserself.driver.quit ()if __name__=='__main__': Unittest.main ()
Selenium webdriver-Action Browser Cookie