Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set path for executable IE drivers in Selenium WebDriver

I am trying to run the following code on my machine (win XP & IE8)

public class bookie {                
  private WebDriver driver;        
  private String baseUrl;         
  private boolean acceptNextAlert = true;        
  private StringBuffer verificationErrors = new StringBuffer();        

  @Before    
  public void setUp() throws Exception {    
    DesiredCapabilities caps = DesiredCapabilities.internetExplorer();    
    caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);    
    driver = new InternetExplorerDriver(caps);     
    baseUrl = "http://book.theautomatedtester.co.uk/";     
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);    
  }

  @Test     
  public void testbookie() throws Exception {    
    System.setProperty("webdriver.ie.driver", "IEDriverServer.exe");    
    driver.get(baseUrl + "/");    
    driver.findElement(By.linkText("Chapter1")).click();    
    driver.findElement(By.id("radiobutton")).click();    
    new Select(driver.findElement(By.id("selecttype"))).selectByVisibleText("Selenium Core");    
    driver.findElement(By.linkText("Home Page")).click();     
    driver.findElement(By.linkText("Chapter2")).click();    
    driver.findElement(By.id("but1")).click();     
    driver.findElement(By.xpath("//input[@value='Sibling Button']")).click();     
    driver.findElement(By.linkText("Index")).click();      
    driver.findElement(By.linkText("Chapter1")).click();     
    new Select(driver.findElement(By.id("selecttype"))).selectByVisibleText("Selenium Grid");     
    driver.findElement(By.linkText("Home Page")).click();      
    driver.quit();
  }

But the stack trace which i was provided is

java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105) at org.openqa.selenium.ie.InternetExplorerDriverService.access$1(InternetExplorerDriverService.java:1) at org.openqa.selenium.ie.InternetExplorerDriverService$Builder.build(InternetExplorerDriverService.java:230) at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:263) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:182) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:159) at bookie.setUp(bookie.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

like image 875
LeonarD Avatar asked Jan 24 '14 06:01

LeonarD


1 Answers

Place the driver in some location like C:\Selenium\iexploredriver.exe

Then

File file = new File("C:/Selenium/iexploredriver.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();

Below line should be first line of setUp() function

System.setProperty("webdriver.ie.driver", "IEDriverServer.exe");   
like image 194
A Paul Avatar answered Sep 30 '22 18:09

A Paul