硒不储存饼干

时间:2018-08-26 10:35:25

标签: python python-3.x selenium automation

我正在尝试自动完成一个我想在口袋妖怪漩涡中取得成功的游戏,当我使用硒登录时,它可以正常工作,但是,当我尝试加载需要用户登录的页面时,被直接发送回登录页面(我已经在selenium之外使用相同的浏览器chrome尝试过)。

这就是我所拥有的

import time
from selenium import webdriver
from random import randint




driver = webdriver.Chrome(r'C:\Program Files (x86)\SeleniumDrivers\chromedriver.exe')  
driver.get('https://zeta.pokemon-vortex.com/dashboard/');
time.sleep(5) # Let the user actually see something!

usernameLoc = driver.find_element_by_id('myusername')
passwordLoc = driver.find_element_by_id('mypassword')

usernameLoc.send_keys('mypassword')
passwordLoc.send_keys('12345')

submitButton = driver.find_element_by_id('submit')
submitButton.submit()

time.sleep(3)

driver.get('https://zeta.pokemon-vortex.com/map/10')
time.sleep(10)

我正在使用python 3.6+,而我今天才刚刚安装了硒,所以它是最新的,如何强制硒保留在cookie上?

1 个答案:

答案 0 :(得分:0)

使用预定义的用户个人资料可能会解决您的问题。这样,您的缓存将被保存,并且不会被删除。

from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data")
driver = webdriver.Chrome(options=options)
driver.get("xyz.com")