My Thoughts: Starting Opera Browser and Internet Explorer (IE) using WebDriver(Selenium2) with example

Wednesday, May 23

Starting Opera Browser and Internet Explorer (IE) using WebDriver(Selenium2) with example


In the previous Post we have discussed how to Open Chrome Browser using WebDriver.

Now it is time for Opera :)

Opera and IE browers are as easy as you work with Firefox Browser.

Opera Browser :

Use the below code to start Opera Browser:
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setCapability("opera.binary","Absolute Path of Opera browser"); 
//Path will be something like
//C:\Users\\AppData\Local\Programs\Opera\opera.exe 
driver = new OperaDriver(capabilities);
Here is the sample code using TestNG framework
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.opera.core.systems.OperaDriver;

public class opera {
 
 WebDriver driver;
 
 @BeforeTest
 public void open(){ 
  DesiredCapabilities capabilities = DesiredCapabilities.opera();
  capabilities.setCapability("opera.binary", " Absolute Path of Opera browser ");
  driver = new OperaDriver(capabilities); 
 }
 
 @Test
 public void startit(){
  driver.get("http://google.com/");  
 }
 
}

Internet Explorer:

First download  IEDriverServer.exe file from here and save it on your local disk.

Now use the below code to start Internet Explorer 
System.setProperty("webdriver.ie.driver", "Path to IEDriverServer.exe");
driver = new InternetExplorerDriver();
Here is the sample code using TestNG framework.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class IeBrowser {
 
 WebDriver driver;

 @BeforeTest
 public void start(){
   System.setProperty("webdriver.ie.driver", "Path to IEDriverServer.exe");
   driver = new InternetExplorerDriver();
 }
 
 @Test
 public void startit(){
  driver.get("http://google.com");
  
 }

}

Note :
Even if you are using 64-bit operating system try to use 32 bit version of IEDriver as there are some known issues with the 64-bit version of IEDriver.  Especially 64 bit driver is too slow .

https://code.google.com/p/selenium/issues/detail?id=5116#makechanges
https://code.google.com/p/selenium/issues/detail?id=3072

No comments:

Post a Comment