我正在使用selenium webdriver,C#。
有没有可能使工作webdriver与Firefox选择文件对话框?或者我必须使用像AutoIt这样的东西?
发布于 2012-01-13 23:12:57
不,WebDriver不能与对话框交互-这是因为对话框是操作系统的域,而不是网页。
我认识一些使用autoit以及.Net提供的Automation API的人。
另一种选择是完全跳过文件对话框,发出POST或GET,但这需要更高级的网站知识以及理解如何构造POST/GET。
你可以试试Webinator,因为它是由WebDriver驱动的,所以它类似于Selenium。它提供了文件对话功能,我用它取得了很大的成功。
发布于 2012-07-13 17:32:30
这是另一个使用remotewebdriver的解决方案,它像魔术一样工作,我喜欢它。
下面是我的类:
driver.findElementByLinkText("Upload Files").click();
driver.setLogLevel(Level.ALL);
System.out.println(driver.getCurrentUrl());
WebElement element = driver.findElement(By.xpath("//input[@name='file_1']"));
LocalFileDetector detector = new LocalFileDetector();
//Now, give the file path and see the magic :)
String path = "D://test66T.txt";
File f = detector.getLocalFile(path);
((RemoteWebElement)element).setFileDetector(detector);
element.sendKeys(f.getAbsolutePath());
//now click the button to finish
driver.findElementByXPath("//html/body/div[9]/div[1]/a/span").click();
发布于 2016-07-20 00:26:00
可以按如下方式完成此操作,并使用Internet Explorer和Chrome驱动程序进行测试和工作
var allowsDetection = this.Driver as IAllowsFileDetection;
if (allowsDetection != null)
{
allowsDetection.FileDetector = new LocalFileDetector();
}
Driver.FindElement(By.Id("your-upload-input")).SendKeys(@"C:\PathToYourFile");
参考https://groups.google.com/forum/#!msg/webdriver/KxmRZ8MkM4M/45CT4ID_WjQJ
https://stackoverflow.com/questions/8851051
复制相似问题