You are on page 1of 7

Selenium Testing Tool

Code:
package selenium;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.chrome.ChromeOptions;

public class TestMITonGoogle {

public static void main(String[] args) {

//0.Configure Selenium to work with this project

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

//0.1 Tell Eclipse to use Selenium

//0.2 Tell this script to use Selenium, Google Chrome and its version as the default
browser

ChromeOptions co = new ChromeOptions();

co.setBrowserVersion("119");

//1. Open Web Browser

WebDriver driver = new ChromeDriver();


//2. Navigate to Google.com

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

//3.Enter Search String "MITWPU" in the search box

WebElement searchBox = null;

searchBox = driver.findElement(By.name("q"));

searchBox.sendKeys("MIT WPU");

//4.Click on Google Search

driver.findElement(By.className("gN089b")).click();

//5.Verify whether the page loads

String title = driver.getTitle();

if(title.contains("MIT WPU")) {

System.out.println("Step 5 Passed");

} else {

System.out.println("Step 5 Failed");

//6.Verify whether the first result is for MIT-WPU

break;

}
Output:

You might also like