Selenium Internet Explorer 8缓存问题

5
当我在Windows XP Internet Explorer 8上运行Selenium测试时,测试不会从头开始。它将使用来自先前运行的cookie /缓存启动测试。当我在Firefox中运行测试时,这种情况并不会发生。 有没有解决这个问题的方法?最好是用Python。 一些想法: -编写脚本,在tearDownClass中删除C:\ Documents and Settings \ Owner \ Local Settings \ Temporary Internet Files中的所有临时文件 -将浏览器设置为Internet Explorer私人模式“* custom C:\ Program Files \ Internet Explorer \ iexplore.exe-private”,而不是“* iehta”(由于我的语法错误,这种方法无效)。 谢谢。
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']",'test+abc010@workflowy.com'  )
    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()
1个回答

1

你可以使用sel.delete_all_visible_cookies()来移除当前域名下的所有 Cookies。如果你有多个域名,可以使用以下代码:

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

请参阅此博客文章以获取更多信息。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接