Welcome back to another post of Selenium Webdriver in this post I will show you how to start default Firefox profile in Selenium Webdriver.
While working with Firefox in Selenium you have noticed that it starts the fresh profile every time so you will not get any cookies, form data and any plugin or add-on, which you have installed on your local browser.
What is Firefox Profile?
Ans- Firefox or any other browser contain your normal data like- saved data, history, cookies, add-on and all information which is generally called Firefox Profile and using Selenium we can access these profiles and operation can be performed.
You can create an own profile and can use throughout your Selenium script execution.
Usage of Default Firefox Profile in Selenium
If you want to start default, profile every time when you execute your test so that you do not have to handle two instances of the same browser then you can do using FirefoxProfile class in Selenium.
I have used the Firefox profile while downloading the file in Selenium so if you have still not visited then check below post for more usage of Firefox Profile.
How to download file in Selenium
If you want to check from where we get default profile.
Step 1- Close all Firefox Instance
Step 2- Open run
Step 3- Type firefox.exe –p
Step 4- Hit enter
Step 5- Check whether you have default profile in the `list. If yes then below code will work fine.
Please use below code to start default Firefox session.
Program to start Default Firefox Profile in Selenium
import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.firefox.internal.ProfilesIni; public class FirefoxDemo { public static void main(String[] args) { // Create object of ProfilesIni class ProfilesIni init=new ProfilesIni(); // Get the default session FirefoxProfile profile=init.getProfile("default"); // Pass the session/profile to FirefoxDriver WebDriver driver=new FirefoxDriver(profile); driver.get("https://learn-automation.com/"); driver.quit(); } }
Output- After running your code you will get Firefox with preinstalled cookies, Add-on and all the details, which saved earlier.
Hope you enjoyed this article if any doubt in Selenium then feels free to post in Selenium Forum.
For any comment or feedback please comment below section.
Leave a Reply