0% found this document useful (0 votes)
76 views

Tutorial SeleniumAutomation STM

This tutorial explains how to automate logging into a Facebook account using Selenium WebDriver in Java. It provides steps to create a Java project in Eclipse, add the necessary Selenium JAR files, and write code to launch Firefox, navigate to Facebook, enter login credentials, and click the login button. The tutorial also provides tips on how to find element IDs to automate interactions with page elements and resolve compilation errors.

Uploaded by

BHAVYA CHAWLA
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

Tutorial SeleniumAutomation STM

This tutorial explains how to automate logging into a Facebook account using Selenium WebDriver in Java. It provides steps to create a Java project in Eclipse, add the necessary Selenium JAR files, and write code to launch Firefox, navigate to Facebook, enter login credentials, and click the login button. The tutorial also provides tips on how to find element IDs to automate interactions with page elements and resolve compilation errors.

Uploaded by

BHAVYA CHAWLA
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Tutorial: Selenium Automation

Using Selenium WebDriver to test elements on Facebook Login Page

This tutorial would help you to login into your Facebook Account using Selenium WebDriver using
FireFox Browser. The code discussed in this tutorial can be easily extended to design test cases to
test the various UI elements of the Facebook Login Page.

Step 1: Create a new Java Project using Eclipse IDE.


(Tested with Eclipse Standard/SDK, Version: Kepler Release)

Step 2: Create a new Package inside it named testingDemo.

Step 3: Create a new class in the testingDemo package, named SeleniumTestingClass.

Copy the code written below: [or use SeleniumTestingClass.java]


package testingDemo;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.By;

public class SeleniumTestingClass {

public static void main(String[] args) {

System.setProperty("webdriver.gecko.driver","D:\\geckodriver.exe");

WebDriver driver= new FirefoxDriver();


driver.get("http://www.facebook.com");

WebElement emailElement = driver.findElement(By.id("email"));


emailElement.sendKeys("your login id here");

WebElement passwordElement = driver.findElement(By.id("pass"));


passwordElement.sendKeys("your password here");

WebElement loginElement = driver.findElement(By.id("u_0_2"));


loginElement.click();

System.exit(0);

}
Important:
 Download 1:

Download the following jar files:

a) selenium-server-standalone-3.6.0.jar
(Link: http://www.seleniumhq.org/download/)

b) client-combined-3.6.0.jar
(Link: http://www.seleniumhq.org/download/)

Add them to your project and add them to the Build Path of the project.

 Download 2:

For interfacing with FireFox browser, you need to download the following jar file and
place it on your system:

a) geckodriver.exe
(Link: https://github.com/mozilla/geckodriver/releases)
[Modify the path for this file accordingly in your code]

Tip:

In case you get a compilation error on the following line for the sendKeys() method:
emailElement.sendKeys("your login id here");

Follow these steps in your Eclipse:

1. Right click on your java project and select Build Path -> Click on
Configure Build Path...
2. In project properties window, Click Java Compiler at the left
panel
3. At the right panel, change the Compiler compliance level from 1.4 to 1.7
(Select which is higher version in your eclipse)
4. Lastly click on Apply and OK
Related Explanation:
In order to extract the unique ids of individual UI elements of a webpage, right click on the UI
element and select “Inspect Element”. You will see some HTML code which gets open in a
window at the bottom of the page. You will also see the selected element as being highlighted
in the code. Now right-click on this selected code and select ‘Copy-> Outer HTML’ and paste
on a notepad.
You will get the unique id of this element which can be used in Java code for referring this
element.

Refer figure below:

You might also like