How to add Firefox Profile to ByPass Login activitiy on Firefox Browser?

Firefox profile is used on selenium scripts to bypass the login activity and to save the time.  For Example, if we are automating facebook, gmail, twitter, etc., User need to add the login activity on the their scripts which will take more time to get in.

To skip the login activity of any webpage, user can add and save their credential details such as login and password information on the firefox profile.

To see the firefox profile - Hold Windows button + R or Goto Run command.
Fx31Profilemgr
Now, we can view the existing profile's. 

If we want to add new profile, click Create Profile.  Then, Check the box of 'Use the selected profile without asking at startup'. Now, click Start Firefox.

Then, Enter the User Name and Click Finish.

Hereafter, By default, whenever we open the browser our profile will be set default by the user name of the profile.  There is two things, one thing is, if no profile is existing, it will be in default mode.  If user created any profile and marked as selected profile is default, Then every time the browser will open withe user profile id.

Ok. We have created the profile now. Now, login with your facebook, gmail, or any other website.

For the below code of the example, I had used www.buffer.com. Hence, I logged in with the user id and password and i saved it using remember password.  

To test this, whenever we open the buffer.com on the profile, it should be automatically redirect to the buffer.com.  Note : When you run the code do not clear the browsing data.

JAVA Syntax : public FirefoxProfile(java.io.File profileDir)

Now, Lets check with the below code. Just copy and run the code. replace your website name, login details.  Also please make sure to change the WebElement if you are using other than buffer.com.

Code:
import org.openqa.selenium.By;
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 FirefoxCustomProfile {
static WebDriver driver;
public static void main(String... args){

//profile initilization
ProfilesIni profile = new ProfilesIni();

//I have created Buffer profile. So i had given Buffer between the double quotes
FirefoxProfile myprofile = profile.getProfile("Buffer");

//Invoke firefox driver and placing profile
driver = new FirefoxDriver(myprofile);

//Naving to buffer.com, Now it should go directly to buffer after logged in
driver.get("http://www.buffer.com");

driver.findElement(By.linkText("Log In")).click();
driver.findElement(By.id("sign-into-account-button")).click();
}
}

No comments:

Post a Comment

Socialize It and Share the post with your friends
SOCIALIZE IT →
FOLLOW US →
SHARE IT →