c# selenium 浏览和上传文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18864450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
c# selenium to browse and upload a file
提问by vysakh
In my selenium c# windows forms application, I have a scenario like uploading a doc/docx file. I have already done uploading in some another case.since it has some text box infront of browse button I uploaded using
在我的 selenium c# windows 窗体应用程序中,我有一个类似上传 doc/docx 文件的场景。我已经在另一种情况下完成了上传。因为它在我上传的浏览按钮前面有一些文本框
IWebElement element = driver.FindElement(By.Id("uploadhere"));
element.SendKeys("C:\Some_Folder\MyFile.txt");
But here now in my present scenario, I cant use this code. My picture below shows the upload file dialog box. I googled many and couldnt find one that suits my need...I can click on browse button but cant select a file. Firebug and selenium IDE seemed not to be useful..
但是现在在我目前的情况下,我无法使用此代码。我下图显示了上传文件对话框。我用谷歌搜索了很多,但找不到适合我需要的……我可以点击浏览按钮,但无法选择文件。Firebug 和 selenium IDE 似乎没有用。
Can anyone help me on this? Any comments would be really appreciated..
谁可以帮我这个事?任何评论将不胜感激..
回答by Praveen Kumar
Since its a OS dialog box you cannot handle it with selenium , you can use java script executor check this link Webdriver: File Upload
由于它是一个操作系统对话框,您无法使用 selenium 处理它,您可以使用 java 脚本执行程序检查此链接 Webdriver: File Upload
回答by Avinash Pande
We can Not handle windows fileOpenDialog through Selenium. we have to use either Javascript executor but some time still it is not possible to use Javascriptexecutor. it won't execute. It gives null value error. Example :
我们不能通过 Selenium 处理 windows fileOpenDialog。我们必须使用任一 Javascript 执行程序,但有一段时间仍然无法使用 Javascript 执行程序。它不会执行。它给出了空值错误。例子 :
If you go to naukri.com on below link http://my.naukri.com/manager/createacc2.php?othersrcp=11499&wExp=Nor
如果您通过以下链接访问 naukri.com http://my.naukri.com/manager/createacc2.php?othersrcp=11499&wExp=N或
<input type="file" id="browsecv" name="browsecv"></input>
to upload the file.
上传文件。
your javascript and selenium wont identify the browse element.
您的 javascript 和 selenium 不会识别浏览元素。
Then we have to use third party tool such as Point Position to compute x & Y coordinate of "browsefile" Button then, we can use C#.Net low level MouseClick handle to click on it or we can use AutoIt tool to handle wondows pop. To know more you can visit on
然后我们必须使用第三方工具如Point Position来计算“ browsefile”按钮的x&Y坐标,然后我们可以使用C#.Net低级MouseClick句柄来点击它,或者我们可以使用AutoIt工具来处理wondows pop。要了解更多信息,您可以访问
http://avinashpandeblogsonseleniumautomation.blogspot.in/2015/06/upload-file-using-selenium-web-driver.htmlyou will get solution with an example.
http://avinashpandeblogsonseleniumautomation.blogspot.in/2015/06/upload-file-using-selenium-web-driver.html你会得到一个例子的解决方案。