Selenium – First script to open Google and search “Hello World”

0
178

Follow 6 steps to configure Selenium with Eclipse

1. Install Java:- Download Java JDK as per your OS from below link:-

https://www.oracle.com/java/technologies/javase-jdk8-downloads.html

Note:- JDK version comes bundled with Java Runtime Environment (JRE), so you do not need to download and install the JRE separately. 

2. Install Eclipse:- Download Eclipse from below link:-

http://www.eclipse.org/downloads/

Along with Eclipse, Intellij & Jboss are also other good options. 

3. Install Selenium WebDriver:- Download Selenium WebDriver Language Binding from below link:-

https://www.selenium.dev/downloads/

4. Configure Eclipse IDE with WebDriver

I.    Create a new project i.e. File > New > Java Project

•    Project Name

•    Check Location to save project

•    Click on Finish button

II. Create a package “newpackage” and a class “clsFirstTest”.

III. Now add Selenium WebDriver JAR’s files by doing Right Click on Project > Properties > Java Build Path > Add External JARs > Select all JAR’s which downloaded at step # 3. 

5. Download Chrome Driver:- Check the version of your browser and download same version of driver and add it in your one folder e.g. Drivers

https://chromedriver.chromium.org/downloads

6. Add the Code in class to launch the browser to launch Google.com and enter “Hello World” .

package SeleniumTraining.Se2MavenProject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class HelloWorldGoogle
{
public static void main(String[] args) {
//Set Chrome Driver Path
System.setProperty(“webdriver.chrome.driver”, “Driver\chromedriver.exe”);
// Initialize browser
WebDriver driver=new ChromeDriver();
// Open Google
driver.get(“https://www.google.com/”);
//Enter Hello World
driver.findElement(By.xpath(“//input[@name=’q’]”)).sendKeys(“Hello World”);
//Print message
}
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here