Selenium webdriver-Action Browser Cookie

Source: Internet
Author: User

#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

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.