1
我是Java和Selenium的新手,遇到此問題需要重新使用瀏覽器會話。Selenium Java重用瀏覽器會話
我周圍搜索,但找不到一個很好的解決方案。 有沒有辦法在Selenium中重用Firefox會話?
我是Java和Selenium的新手,遇到此問題需要重新使用瀏覽器會話。Selenium Java重用瀏覽器會話
我周圍搜索,但找不到一個很好的解決方案。 有沒有辦法在Selenium中重用Firefox會話?
你有兩個選擇:
保存的cookies,並在司機
driver = new FirefoxDriver();
for(Cookie cookie : allCookies)
{
driver.manage().addCookie(cookie);
}
的每個創作檢索它們保存到本地瀏覽器配置文件,然後加載它
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
File profileDirectory = new File("c://mach//lib//prof");
FirefoxProfile profile = new FirefoxProfile(profileDirectory);
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
WebDriver driver = new FirefoxDriver(capabilities);
Tx的幫助,但如何abo ut保存firefox配置文件或保存cookie?我無法做到這一點。 – Brito
您是否嘗試將cookie保存爲一個集合:'Set cookies = driver.manage()。getCookies();'然後檢索它們? Firefox會將配置文件保存到tmp文件夾中,然後在關機時將其刪除,但您仍可以進入此tmp文件夾並將配置文件保存在文件中。參考這裏:http://stackoverflow.com/questions/30435749/python-selenium-firefox-cant-start-firefox-with-specified-profile-path/33350778#33350778。另外,你可以這樣做:http://stackoverflow.com/questions/13033071/save-firefox-profile-generated-by-selenuim-web-driver –
當我嘗試上面的代碼爲cookies,我得到了它的錯誤「 allCookies無法解析爲變量「任何想法? – Brito