Selenium Internet Explorer 8 缓存问题
当我在Windows XP的Internet Explorer 8上运行我的Selenium测试时,测试并没有从头开始。它会使用上一次运行时的cookies和缓存来开始测试。而在Firefox上运行测试时就没有这个问题。
有没有人有解决办法?最好是用Python来实现。
我想到的一些方法:
- 在tearDownClass中运行一个脚本,删除以下路径下的所有临时文件:C:\Documents and Settings\Owner\Local Settings\Temporary Internet Files
- 不用“*iehta”作为浏览器,而是设置为Internet Explorer的私密模式“*custom C:\Program Files\Internet Explorer\iexplore.exe -private”(--这个方法没有成功,可能是我的语法有问题?
谢谢。
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()
这个命令,它会删除当前网站创建的所有cookie。如果你有多个网站,可以使用下面的代码:
def clean_history(sel, domains):
temp = sel.get_location()
for domain in domains:
sel.open(domain)
sel.delete_all_visible_cookies()
sel.open(temp)
想了解更多信息,可以查看 这篇博客。