Thursday 1 May 2014

Working with different browser using Selenium Web Driver

For firfox browser

We no need to set any system property for Firefox fox browser. we can use directly after download selenium.


import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;


public class Testing1 {

public static void main(String[] args) {

FirefoxDriver fd=new FirefoxDriver();
fd.get("http://google.com");
System.out.println(fd.getTitle());
fd.close();

}

}


***************************

For Chrome Browser

The above code alone is not work. we need to set system property as per in below step.

1)Download the chrome driver from selenium download.Then save in location "E:\chrome\ChromeDriver.exe"
2)And add the system property as
System.setProperty("Webdriver.chrome.driver",""E:\chrome\ChromeDriver.exe")

we can see the path "Webdriver.chrome.driver" in Error message if we are not download the ChromeDriver.exe file.


3) so below code is work for chrome browser

import org.openqa.selenium.Chrome.ChromeDriver;


public class Testing1 {

public static void main(String[] args) {
System.setProperty("Webdriver.chrome.driver",""E:\chrome\ChromeDriver.exe")

ChromeDriver fd=new ChromeDriver();
fd.get("http://google.com");
System.out.println(fd.getTitle());
fd.close();

}

}


*******************************************


For Internet Explorer Browser 8

we need to set system property as per in below step.

1)Download the IE driver from selenium download.Then save in location "E:\IE\InternetExplorerDriver.exe"

2)And add the system property as
System.setProperty("webdriver.ie.driver",""E:\IE\InternetExplorerDriver.exe")

we can see the path "webdriver.ie.driver" in Error message if we are not download the InternetExplorerDriver.exe file.


3) so below code is work for Internet Explorer

import org.openqa.selenium.ie.InternetExplorerDriver;


public class Testing1 {

public static void main(String[] args) {
System.setProperty("webdriver.ie.driver",""E:\IE\InternetExplorerDriver.exe")
InternetExplorerDriver fd=new InternetExplorerDriver();
fd.get("http://google.com");
System.out.println(fd.getTitle());
fd.close();

}

}

1 comment:

  1. This blog post is a game-changer. The author's unique perspective challenges conventional wisdom and opens up new possibilities color blind test Their unique perspective allowed them to create masterpieces that transcend traditional color schemes.

    ReplyDelete