问题描述
我使用webdriver的硒,C#。
I'm using selenium webdriver, C#.
时有可能使与Firefox工作的webdriver选择文件对话框?
或我必须使用像AutoIt的?
Is it possible to make work webdriver with Firefox select file dialog?Or i must use something like autoit?
推荐答案
如果您要选择要上传硒2支持的文件HTML文件输入。例如:
If you are trying to select a file for upload Selenium 2 supports HTML file inputs. For example:
HTML
<input type="file" id="uploadhere" />
硒代码
IWebElement element = driver.FindElement(By.Id("uploadhere"));
element.SendKeys("C:\\Some_Folder\\MyFile.txt");
基本上你的类型(与的SendKeys
)完整的文件路径文件输入元素。硒处理文件选择对话框,让你。
Basically you "type" (with SendKeys
) the full file path to the file input element. Selenium handles the file selection dialog for you.
不过,如果你想操作一个任意的文件选择对话框,然后像安德斯说,你到外面去硒。
However if you want to manipulate an arbitrary file selection dialog, then like Anders said, you have to go outside of Selenium.
这篇关于硒的webdriver和浏览器选择文件对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!