Reputation: 73
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();
}
Upvotes: 1
Views: 147
Reputation: 209
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
Upvotes: 1