Home Ask Login Register

Developers Planet

Your answer is one click away!

bigJava February 2016

Exception on running IE web Driver

I'm new in java, using it for automatic tests. Please help me what I'm doing wrong with this code?

public static WebDriver driver = null;

public static WebDriver getDriver() {
if (driver == null) {

File fileIE = new File("src//test/java/iedriver.exe");
            System.setProperty("webdriver.ie.driver", fileIE.getAbsolutePath());
   }
try {
 driver = new InternetExplorerDriver();
    }
 catch (Exception e)
 e.printStackTrace();
}

Answers


Evg Evg February 2016

Try to add DesiredCapabilities to your code.

if (driver == null) {

    File fileIE = new File("src//test/java/iedriver.exe");
            System.setProperty("webdriver.ie.driver", fileIE.getAbsolutePath());                

            DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();

            try {                                       
                driver = new InternetExplorerDriver(ieCapabilities);                                        
            } catch (Exception e) {                 
                throw new RuntimeException(e);
            }
       }

the DesiredCapabilities help to set properties for the WebDriver. A typical usecase would be to set the path for any type of the WebDriver if your local installation doesn't correspond to the default settings.

You can read about class DesiredCapabilities and about its' using here: DesiredCapabilities

Post Status

Asked in February 2016
Viewed 2,873 times
Voted 13
Answered 1 times

Search




Leave an answer


Quote of the day: live life