我正在使用 Selenium WebDriver 和 Java,我需要自动化文件上传功能。我尝试了很多,但是当单击“浏览”按钮并打开一个新窗口时,脚本会停止进一步执行,并且会卡住。我尝试了 FireFox 和 IE 驱动程序,但没有成功。
我还尝试通过调用 autoit exe 文件,但是当单击“浏览”按钮打开新窗口时,特定语句
Runtime.getRuntime().exec("C:\\Selenium\\ImageUpload_FF.exe")
无法被执行。请帮忙
这应该适用于 Firefox、Chrome 和 IE 驱动程序。
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://localhost:8080/page");
File file = null;
try {
file = new File(YourClass.class.getClassLoader().getResource("file.txt").toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
}
Assert.assertTrue(file.exists());
WebElement browseButton = driver.findElement(By.id("myfile"));
browseButton.sendKeys(file.getAbsolutePath());
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)