Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views4 pages

Selenium 1

Uploaded by

abhinandpcdance
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Selenium 1

Uploaded by

abhinandpcdance
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PROGRAM 1: LAUNCH A WEB BROWSER AND OPEN A WEBSITE

Aim:Write a selenium java program to launch a web browser and open a website.

package project;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class project {

WebDriver driver;

public void launchBrowser() {

System.setProperty("webdriver.chrome.driver","C:\\SELENIUMJAVA\\chromedriver\\chromedriver.exe");

driver=new ChromeDriver();

driver.get("https://www.amazon.in/");}

public static void main(String[] args) {

project obj=new project();

obj.launchBrowser();}}
PROGRAM 2:CHECK THE TITLE OF THE WEBSITE

Aim:write a selenium java program to check the title of a website

package project;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class project1 {

static WebDriver driver;

public void Title_verify() {

System.setProperty("webdriver.chrome.driver"," C:\\SELENIUM JAVA\\chromedriver\\chromedriver.exe ");

driver=new ChromeDriver();

driver.get("https://www.google.com/");

String exptitle="google.com";

System.out.println("Expected title:"+exptitle);

String acttitle=driver.getTitle();

System.out.println("Actual title:"+acttitle);

if(exptitle.equals(acttitle))

{ System.out.println("PASS");}

else { System.out.println("FAIL");}}

public static void main(String[] args)

{ project1 obj=new project1();

obj.Title_verify();}}
PROGRAM 3:WEBSITE NAVIGATION

Aim:write a selenium java program to navigate across the website

package project;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class project3 {
static WebDriver driver;
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver"," C:\\SELENIUM JAVA\\chromedriver\\chromedriver.exe ");
driver=new ChromeDriver();
driver.navigate().to("https://www.amazon.in");
driver.findElement(By.linkText("Mobiles")).click();
driver.navigate().back();
driver.navigate().forward();
driver.navigate().refresh();
driver.close();}}

PROGRAM 4:SEARCH KEYWORD IN THE WEBSITE

Aim:write a selenium java program to search a keyword in the website

package project;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class project4 {

static WebDriver driver;

public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver"," C:\\SELENIUM JAVA\\chromedriver\\chromedriver.exe ");

driver=new ChromeDriver();

driver.get("https://www.google.com");

String src=driver.getPageSource();

if(src.contains("Gmail"))

{ System.out.println("pass");}

else{ System.out.println("fail");}

driver.close();}}
PROGRAM 5:FACEBOOK AUTOMATION

Aim:write a selenium java program to automate facebook login

package project;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebElement;
public class project5 {
static WebDriver driver;
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver"," C:\\SELENIUM JAVA\\chromedriver\\chromedriver.exe ");
driver=new ChromeDriver();
driver.get("https://www.facebook.com/");
WebElement emailInput = driver.findElement(By.id("email"));
emailInput.sendKeys("[email protected]");
WebElement passwordInput = driver.findElement(By.id("pass"));
passwordInput.sendKeys("Angamaly@25");
WebElement loginButton = driver.findElement(By.name("login"));
loginButton.click();
driver.close();}}

You might also like