本文为霍格沃兹测试开发学社学员学习笔记分享
原文链接:https://ceshiren.com/t/topic/27165
cookie是一些数据,存储于用户电脑的文本文件中
当web服务器想浏览器发送web页面时,在链接关闭后,服务端不会记录用户信息
def test_get_cookies(self):
self.driver.get('https://work.weixin.qq.com/wework_admin/frame')
time.sleep(20)
cookies = self.driver.get_cookies()
print(cookies)
# 将cookie写入文件
with open("cookies.yaml", "w") as f:
yaml.safe_dump(cookies, f)
def test_add_cookies(self):
self.driver.get('https://work.weixin.qq.com/wework_admin/frame')
# 从文件中读取cookie
cookies = yaml.safe_load(open("cookies.yaml"))
# 植入cookies
for i in cookies:
self.driver.add_cookie(i)
time.sleep(3)
self.driver.refresh()
time.sleep(10)