如何使用 Web 驱动程序在 Firefox 中实现记住我的自动化? [英] How to implement Remember me automation in Firefox with web driver?

查看:28
本文介绍了如何使用 Web 驱动程序在 Firefox 中实现记住我的自动化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Web 驱动程序在 Firefox 中实现记住我"自动化?我使用的是网络驱动程序 2.20、Eclipse IDE、Firefox 9.0

How to implement "Rememeber me" automation in Firefox with web driver? I am using web driver 2.20, Eclipse IDE, Firefox 9.0

推荐答案

我知道您需要一个适用于 Firefox 的解决方案,但我有以下适用于 Chrome 的工作版本.您可以参考此链接以获取 Firefox 解决方案:如何在不清除 cookie 或缓存的情况下启动 Selenium RemoteWebDriver 或 WebDriver?

I understand you need a solution for firefox, but I have the below working version for Chrome. You can refer this link for a firefox solution: How to start Selenium RemoteWebDriver or WebDriver without clearing cookies or cache?

对于 Chrome (config):您必须设置 user-dir 的路径,这将在您第一次登录后保存所有登录信息.下次再次登录时,将使用用户目录中的登录信息.

For Chrome (config): You have to set the path to user-dir which will save all the login info after you login for the first time. The next time you login again, login info from the user-dir will be taken.

System.setProperty("webdriver.chrome.driver", "res/chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("start-maximized");
options.addArguments("user-data-dir=D:/temp/");
capabilities.setCapability("chrome.binary","res/chromedriver.exe");
capabilities.setCapability(ChromeOptions.CAPABILITY,options);
WebDriver driver = new ChromeDriver(capabilities);

首次登录:

driver.get("https://gmail.com");
//Your login script typing username password, check 'keep me signed in' and so on

关闭驱动程序(不要退出):

Close the driver (do NOT quit):

driver.close(); 

重新初始化驱动程序并导航到该站点.不应再次要求您输入用户名和密码:

Re-initialize the driver and navigate to the site. You should not be asked for username and password again:

driver = new ChromeDriver(capabilities);
driver.get("http://gmail.com");

可以使用 Firefox 配置文件为 Firefox 实现上述内容.

The above can be implemented for firefox using a firefox profile.

这篇关于如何使用 Web 驱动程序在 Firefox 中实现记住我的自动化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆