Sunday 27 October 2013

How to launch internet explorer browser using selenium webdriver in Java?

You can download the IE driver from the link - http://docs.seleniumhq.org/download/. IEDriverServer supports 32 bit as well as 64 bit Internet Explorer.

Setting the driver parameters

Ensure that Server path is included in System PATH variable or set the property as shown below.

System.setProperty("webdriver.ie.driver", "F:\\selenium\\java\\iedriver.exe");

Other properties that we can set are given below.
  1. webdriver.ie.driver.host 
  2. webdriver.ie.driver.loglevel 
  3. webdriver.ie.driver.logfile 
  4. webdriver.ie.driver.silent 

Browser Settings

Ensure that Protected mode settings for all zones should be same and for IE10 and above, enhanced protected mode must be disabled and the browser zoom level must be set to 100%.

For IE 11 only, You will need to edit below registry keys.

For 32-bit Windows, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. For 64-bit Windows, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.

Please note that the FEATURE_BFCACHE subkey is optional and and should be created if not present. Inside this key, you need to create a DWORD value with name = iexplore.exe and value = 0.

To clean IE Session

Ensure that you pass below capability - ie.ensureCleanSession with true value.

Example code to launch IE


You can use below example/code to start the new IE session in Java using selenium web driver.

package seleniumtest;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.*;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;

public  class MainTest {
      
      
       public static void main(String[] args) {
      
                 WebDriver driver =null;
                 System.setProperty("webdriver.ie.driver", "F:\\selenium\\java\\iedriver.exe");
                 driver = new InternetExplorerDriver();
                 driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
                 driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
             
             
                     try{                         
                                                       driver.get("http://register.rediff.com/register/register.php");
                           driver.findElement(By.name("name")).sendKeys("ff89");
                          
                           driver.findElement(By.name("name")).sendKeys(Keys.TAB);
                           Thread.sleep(3000);
                          
                           //driver.findElement(By.name("passwd")).click();
                           Actions builder = new Actions(driver);
                          

                           WebElement e = driver.findElement(By.cssSelector("#sk"));
                           //build the action chain.
                           Action doubleclick = builder.doubleClick(e).build();

                           //perform the double click action
                           doubleclick.perform();

                          
                           driver.switchTo().alert().accept();
                           Thread.sleep(4000);
                           //driver.navigate();
                         //driver.navigate("http://www.google.com");
                          
              }catch(Exception e){
                    
                     System.out.println(e.toString());
              }
                    
                    
              finally{
                     driver.close();
                     driver.quit();
              }  
       }      
}
Please note that we need to set the system property webdriver.ie.driver
We have to give the path of IEdriver.exe
Once you have created driver object, you can use its methods to automated the browser tasks.
You can find more updated information here - instructions on IE configuration.

You may also like to read below topics.
  1. Press key in Selenium Webdriver in Java
  2. Read Table Data in Selenium Webdriver in Java
  3. Take the screenshot in Selenium Webdriver in Java
  4. Execute JavaScript in Selenium Webdriver in Java
  5. Handle multiple browser windows in Selenium Webdriver in Java
  6. Double-Click on the Element in Selenium Webdriver in Java
  7. Exceptions in Selenium Webdriver in Java
  8. Synchronization in Selenium Webdriver in Java

What do you think on above selenium topic. Please provide your inputs and comments. Thanks

No comments:

Post a Comment

Buy Best Selenium Books

Contributors