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,950 points
1,271 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
+1 vote
1 answer

How can I automate the process of adding iPhone to cart in Flipkart using Selenium(java),Page Object Model and TestNG? Also validate if product is added and available in cart?

Hey check this https://www.edureka.co/community/47160/automate-purchase-adding-book-cart-flipkart-using-selenium? It deals with a similar ...READ MORE

answered Jan 13 in Selenium by Karan
• 15,680 points
2,568 views
0 votes
1 answer

What is the process of installing Selenium IDE?

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

answered May 13, 2019 in Selenium by Avantika
55 views
0 votes
2 answers

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,510 points
3,474 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,487 views
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,890 points
2,566 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
2,801 views
+9 votes
15 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,360 points
118,365 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
• 13,180 points
6,356 views