Java Scrap Book  

Selenium WebDriver Important Question

How to setup Selenium Webdriver Development environment


1. Download the chrome driver from ChormeDriver download link and copy the chrome driver jar at you local directory . For example chrome driver is at /direcotory/javajar/ directory in your computer.

2.Download the Selenium WebDriver jar at http://docs.seleniumhq.org/download/.
3.Add Selenium WebDriver jar in the Java project.
4.Create a WebDriverDemo class.


Sample code for Webdriver demo


import  org.openqa.selenium.By;
import  org.openqa.selenium.WebDriver;
import  org.openqa.selenium.chrome.ChromeDriver;

public class WebDriverDemo {
public static void main(String [] args){

WebDriver driver;
System.setProperty("webdriver.chrome.driver","/directory/javajar/chromedriver");
driver = new ChromeDriver();
driver.get("http://google.com");
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.quit();
}

}

Table of Content

How to maximize Windows in WebDriver

you can maximize web browser by driver by following code.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class TestWindows{
public static void main(String [] args){

WebDriver driver;

System.setProperty("webdriver.chrome.driver",//ChromeDriverLocation);

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

driver.manage().window().maximize(); // this step maximize the windows

try {

Thread.sleep(10000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

driver.quit();

}

Table of Content