Selenium how to save chrome session

Find session dir

You can find the corresponding path in this blog.
Can't find the Google Chrome User Data Directory in Mac OSX Lion

Mac path: /Users/domina/Library/Application Support/Google/Chrome/Default

Remember to copy this folder to a new temporary directory to avoid any interference with the login process.

Code part

ChromeOptions options = new ChromeOptions();

options.addArguments("--user-data-dir=/Users/user/Desktop/temp/Default");

WebDriver driver = new ChromeDriver(options);
driver.get("http://mg.world.qeeq.cn/order/order.php");
String userInput = ConsoleUtil.getUserInput("");
driver.quit();

When you use WebDriver for the first time to open a site, it may still require you to log in. I assume this is because some data does not match, but it doesn't matter. When you try to run your code for the second time, you will find that it doesn't need login.

Some refs

How to save the browser sessions in Selenium

# Java  selenium 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×