Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Internet Explorer 8 caching issues

when I run my Selenium test on Win XP Internet Explorer 8 , the test doesn't start fresh. It will start the test using the cookies/cache from a previous run. This does not happen when I run the test in Firefox. Does anyone have a workaround for this? Preferably in Python
Some of my ideas:
- have a script run in the tearDownClass that deletes all temporary files in: C:\Documents and Settings\Owner\Local Settings\Temporary Internet Files
- instead of "*iehta" as the browser I set it to Internet Explorer private mode "*custom C:\Program Files\Internet Explorer\iexplore.exe -private" (--that didn't work due to my syntax being off?

Thank you.

import unittest, inspect, time, re,  os
from selenium import selenium

class TESTVerifications(unittest.TestCase):
@classmethod
def setUpClass(self):

    self.selenium = selenium("localhost", 4444, "*iehta", "https://workflowy.com/")
    self.selenium.start() 
    self.selenium.set_timeout("60000")
    print("setUpClass")      
    self.selenium.window_maximize()
    self.selenium.open("/")


def setUp(self):
    self.verificationErrors = []


def test_login_6(self):
    sel = self.selenium
    sel.open("/") 
    sel.type("css=input[id='id_username']",'[email protected]'  )
    sel.type("css=input[id='id_password']",'password')
    sel.click("css=form[id='login'] > input.submit")
    sel.wait_for_page_to_load("60000")
    self.failUnless(sel.is_element_present("id=logout"))


def tearDown(self):
    #self.selenium.stop()
    self.assertEqual([], self.verificationErrors,"Results: " + str(self.verificationErrors))
@classmethod    
def tearDownClass(self):

    self.selenium.stop()
    print("tearDownClass")

if __name__ == "__main__":
unittest.main()
like image 808
HRVHackers Avatar asked Nov 13 '22 16:11

HRVHackers


1 Answers

You can use sel.delete_all_visible_cookies() which will remove any cookie created by the current domain. If you have multiple domains, you can use the following:

def clean_history(sel, domains):
    temp = sel.get_location()
    for domain in domains:
        sel.open(domain)
        sel.delete_all_visible_cookies()
    sel.open(temp)

See this blog post for more information.

like image 124
shamp00 Avatar answered Jan 02 '23 06:01

shamp00