在cookie中添加标签,实现登录灰度环境功能
调用idriver.add_cookie(cookie_dict=cookie1)
具体代码:
from selenium import webdriver
idriver = webdriver.Chrome()
idriver.get('https://www.baidu.com/')
cookie1 = {
"domain": "baidu.com",
"name": "xxxxx",
"value": "xxxxx"
}
idriver.add_cookie(cookie_dict=cookie1)
idriver.maximize_window()
time.sleep(3)
idriver.refresh()
cookie_all = idriver.get_cookies()
print(cookie_all)
text = idriver.find_element_by_xpath("//*[@class='login-context']").text
print(text)
if text=='开发版':
print('登录成功')
else:
print('登录失败')