我是java的新手,用它进行自动测试。请帮助我解决这个代码我做错了什么?
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();
}
答案 0 :(得分:1)
尝试将DesiredCapabilities添加到您的代码中。
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);
}
}
DesiredCapabilities有助于设置WebDriver的属性。如果您的本地安装与默认设置不对应,典型的用例是为任何类型的WebDriver设置路径。
您可以阅读类DesiredCapabilities 及其“使用此处:DesiredCapabilities