Automate the login process of facebook login.

+3 votes
I am trying to automate the login process of facebook. Such that it directly takes the user id and password and logs in the account. I am new to selenium so can someone help me doing this? Thank you in advance.
Dec 18, 2018 in Selenium by Anjali
• 2,930 points
147 views
@User, is the person supposed to enter the username password externally? i.e. user should input the username and password?

1 answer to this question.

+3 votes

Hey @user, you can simply use findelements and the locator ID to get this done. In facebook they have a locator ID for each of the textbox and the buttons. 

Here is the code I used to do this:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Handsonsel {
     public static void main(String[] args) throws InterruptedException
     {
          System.setProperty("webdriver.chrome.driver","Yourpath\\chromedriver.exe");
          WebDriver driver = new ChromeDriver();
          driver.manage().window().maximize();
          driver.get("https://www.facebook.com");
          driver.findElement(By.id("email")).sendKeys("yourusername@gmail.com");
          driver.findElement(By.id("pass")).sendKeys("password");
          Thread.sleep(5000);
          driver.findElement(By.id("u_0_2")).click(); 
          Thread.sleep(7000);
     }
}

Hope this helps.

answered Dec 18, 2018 by Nabarupa

Related Questions In Selenium

+1 vote
1 answer
0 votes
2 answers
0 votes
1 answer

What is the process of installing Selenium IDE?

Hello Tarang, follow these steps to install ...READ MORE

answered May 13 in Selenium by Avantika
17 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
543 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
877 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
535 views
+9 votes
14 answers

How to automate gmail login process using selenium webdriver in java?

Check the below code: Here is the working ...READ MORE

answered Apr 24, 2018 in Selenium by Vardy
• 2,250 points
58,350 views
+1 vote
2 answers

How to get the title of a webpage using Selenium Java?

Essentially, driver.getTitle(); function can be used to ...READ MORE

answered Dec 17, 2018 in Selenium by Vardhan
• 12,450 points
241 views