2012-07-11 40 views
1

如何使用網絡驅動程序在Firefox中實現「Rememeber me」自動化?我正在使用Web驅動程序2.20,Eclipse IDE,Firefox 9.0如何實現使用web驅動程序在Firefox中記住自動化?

+0

記住我自動化是什麼意思?請添加更多詳情。 – vidit 2012-07-11 16:31:35

+0

我有用戶名,密碼和記憶複選框登錄頁面。通過選中記錄複選框並關閉瀏覽器來自動登錄。如果我再次嘗試登錄,它會要求我提供憑據。 預期行爲:無需申請憑據即可登錄。 在IE中它工作正常,但在Firefox中,rememberme cookie被清除,並且不會登錄。 – ShravRao 2012-07-20 11:41:07

回答

0

您遇到這種情況的原因是因爲每次啓動firefox時,webdriver都會創建一個沒有cookie的新匿名配置文件。你可以讓它使用一個特定的配置文件,它應該保留cookie。

File profileDir = new File("path/to/profile"); 
FirefoxProfile profile = new FirefoxProfile(profileDir); 
WebDriver driver = new FirefoxDriver(profile); 

FirefoxProfile有許多其他選項,如添加擴展名和全部。

+0

已創建自定義配置文件並使用相同的配置文件,但它仍在清除cookie。 – ShravRao 2012-07-23 12:33:02

0

我知道你需要一個Firefox的解決方案,但我有Chrome的以下工作版本。你可以參考這個鏈接的Firefox解決方案:How to start Selenium RemoteWebDriver or WebDriver without clearing cookies or cache?

對於Chrome(config):你必須設置路徑到user-dir,這將保存所有的登錄信息,第一次登錄後。下一次再次登錄時,將從用戶目錄登錄信息。

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 

關閉驅動程序(不退出):

driver.close(); 

重新初始化驅動器,然後導航到該網站。你不應該再次被要求輸入用戶名和密碼:

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

以上可以使用firefox配置文件爲Firefox實現。

相關問題