python - 如何避免每次重新登录我的帐户,Selenium Python mac

标签 python macos selenium selenium-webdriver webdriver

我正在学习 Selenium(使用我的本地计算机),需要使用它来访问我的帐户(FB、gmail 等),并且希望使用它而不必每次都输入我的用户 ID 和密码。

有没有办法:

1) 将脚本中的所有说明应用于我现有的 chrome session

2)以某种方式让加载的新窗口记住我的用户名/密码(这似乎使用现有的 Chrome session ,但我不确定如何)

到目前为止我所拥有的:

(我不确定我的个人资料是否应包含我保存的 Google 和 FB 等网站的凭据,但我不明白为什么不这样做)

chrome_options = Options()
chrome_options.add_argument("--user-data-dir=/Users/username/Library/Application Support/Google/Chrome/Default")
driver = webdriver.Chrome(chrome_options=chrome_options)

这会打开一个新窗口,其中包含我的一些凭据,但此后会因错误而崩溃。

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Mac OS X 10.9.5 x86_64)

最佳答案

你可以这样做

browser = webdriver.Firefox()
browser.get("https:one_url.com")

time.sleep(1)

# Login to this one_url.com
username = browser.find_element_by_xpath("find username field")
password = browser.find_element_by_class_name("find password field")
username.send_keys("user")
password.send_keys("password")
login_attempt = browser.find_element_by_xpath("find submit button")
login_attempt.click()
time.sleep(5)

# enter into another web without login
browser.get("https://one_url/profile.com")
time.sleep(5)
# one more 
browser.get("https://one_url/profile.com")
time.sleep(5)

关于python - 如何避免每次重新登录我的帐户,Selenium Python mac,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29225271/

相关文章:

java - Mac 上的 Selenium Java - 按命令按钮 + 单击//或按鼠标中键

ruby - capybara 元素此时不可点击

python - 使用来自不同数据帧的数据规范数据帧中的数据

c - sysctl() 的参数是什么?

python - 有条件的 pandas groupby

android - 安装没有成功。无法安装该应用程序。由于 : '-26' Retry 安装失败

python - 将 adblock 添加到 Chrome python selenium webdriver 时出错

java - 如何通过 Java 脚本弹出窗口登录 Jmeter

python - 操作系统错误 : [Errno 8] Exec format error when running subprocess. 打开

python - 从 RDD 中的单词过滤 Spark 数据框中的行