以下代码为什么不能将 driver1的cookie加载到driver2里呢?如果我将代码换成谷歌浏览器对象,其他部分一样的代码可以成功,为什么ie浏览器就不行呢?而且driver1和driver2是在一个域名下的。
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.ie.options import Options
# from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import NoSuchElementException,SessionNotCreatedException
iedriver = "C:\Iedriver\IEDriverServer_Win32_3.141.0.exe"
os.environ["webdriver.ie.driver"]=iedriver
ie_options = Options()
ie_options.ignore_protected_mode_settings = True
caps = DesiredCapabilities.INTERNETEXPLORER.copy()
caps['ignoreProtectedModeSettings'] = True
caps['IntroduceInstabilityByIgnoringProtectedModeSettings'] = True
driver1 = webdriver.Ie(iedriver,options=ie_options, desired_capabilities=caps)
driver1.implicitly_wait(10)
#电子公文系统登录url
login_url = 'http://10.158.3.30/gwcl/default.aspx'
driver1.get(login_url)
driver1.find_element_by_id('uu').click()
driver1.find_element_by_id('uu').clear()
driver1.find_element_by_id('uu').send_keys('111')
driver1.find_element_by_id('ww').click()
driver1.find_element_by_id('ww').clear()
driver1.find_element_by_id('ww').send_keys('222')
driver1.find_element_by_id('bt_qd').click()
time.sleep(3)
# 获取登陆后的Cookie组成的列表
cookie = driver1.get_cookies()
print(cookie)
# 关闭浏览器
driver1.close()
# 实例化第2个浏览器对象
driver2 = webdriver.Ie(iedriver)
# 添加目标页面链接
driver2.get('http://10.158.3.30/gwcl/oagwcl.aspx')
for c in cookie:
driver2.add_cookie(c)
driver2.get('http://10.158.3.30/gwcl/oagwcl.aspx')
time.sleep(10)