Once we have configured Selenium jar files in to Eclipse (refer post: Downloading Selenium WebDriver Jars and configuring in eclipse), We are now good to start with Basic programs using Selenium.
We write the java program for selenium test in a java class. So, let us create one java class.
Right click on Package -> New -> Class (If you don’t find Class over there, then go to Other, and search for Java class there)
Give some meaningful name to the class and click on Finish.
The first basic thing is, we need to create driver of the web browser which will drive the flow.
Here I am using Mozilla Firefox driver.
Below is the sample code for my first selenium test where I am navigating to www.google.com and finding out the Title of the page.
Once the code is written in a class file, right click on it, select Run AS – > Java Application
Sample code –
package basicsOfSelenium;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FirstSeleniumTest {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.navigate().to("https://www.google.co.in");
String TitleOfPage = driver.getTitle();
System.out.println("Title of Current page is : "+TitleOfPage);
driver.close();
}
}
Sample Output:
Title of Current page is : Google
Good luck for your beginning
Do post your comments for any questions / suggestions.
samantha
admin_prasee