硒2 +另一个文件上传
嗯,我知道硒世界充满了文件上传线程,这是我今天遇到的但到目前为止还无法解决的问题。虽然过去通过使用FF浏览器在文件上传的文件输入文本框中输入来解决这些问题。
所以首先没有文件输入框。只需一个按钮,就会弹出一个窗口来选择文件,一旦您选择了文件,上传就会开始。 html 看起来像 -
<div id="container" style="position: relative;">
<div id="filelist"></div>
<br>
<a id="pickfiles">
<input type="button" name="Photos" value="Pick a File"></a>
<div id="p15tlsibt1185d1pi41tbd16c31a0n0_flash_container" style="position: absolute; top: 21px; background: none repeat scroll 0% 0% transparent; z-index: 99999; width: 86px; height: 18px; left: 0px;" class="plupload flash"><object width="100%" height="100%" data="/CKFinder/upload/content/runtimes/plupload.flash.swf" type="application/x-shockwave-flash" style="outline: 0pt none; background-color: transparent;" id="p15tlsibt1185d1pi41tbd16c31a0n0_flash"><param value="/CKFinder/upload/content/runtimes/plupload.flash.swf" name="movie"><param value="id=p15tlsibt1185d1pi41tbd16c31a0n0" name="flashvars"><param value="transparent" name="wmode"><param value="always" name="allowscriptaccess"></object></div></div>
所以我尝试使用 id/name 等来单击但无济于事。我尝试了这样的点击 -
Commons.clickById(webDriver, "pickfiles")
但页面上没有任何反应。
我也尝试过 - 此处发布的代码片段使用 java 脚本执行 -
但无济于事。我总是遇到错误提示 -
System.InvalidOperationException : arguments[0].click is not a function (UnexpectedJavaScriptError)
有什么建议吗?
Well I know that selenium world is full of file upload threads, and this is something which I came across today and have not been able to solve so far. Though have solved these issues in past by typing in the file input text box of file upload using FF browser.
So first of all there is no file input box. It is just one button which brings a pop up to select a file and as soon as you pick the file, upload begins own its on. html looks as -
<div id="container" style="position: relative;">
<div id="filelist"></div>
<br>
<a id="pickfiles">
<input type="button" name="Photos" value="Pick a File"></a>
<div id="p15tlsibt1185d1pi41tbd16c31a0n0_flash_container" style="position: absolute; top: 21px; background: none repeat scroll 0% 0% transparent; z-index: 99999; width: 86px; height: 18px; left: 0px;" class="plupload flash"><object width="100%" height="100%" data="/CKFinder/upload/content/runtimes/plupload.flash.swf" type="application/x-shockwave-flash" style="outline: 0pt none; background-color: transparent;" id="p15tlsibt1185d1pi41tbd16c31a0n0_flash"><param value="/CKFinder/upload/content/runtimes/plupload.flash.swf" name="movie"><param value="id=p15tlsibt1185d1pi41tbd16c31a0n0" name="flashvars"><param value="transparent" name="wmode"><param value="always" name="allowscriptaccess"></object></div></div>
So I tried using id/name of etc to click but of no avail. I tried clicks like these -
Commons.clickById(webDriver, "pickfiles")
But nothing happens on page.
I also tried - code snippet posted here which uses java script exectuion -
cant click button which opens file attachment dialog
but of no avail. I always encounter error stating -
System.InvalidOperationException : arguments[0].click is not a function (UnexpectedJavaScriptError)
Any Suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
并使用 autoit 得到了解决方案,这是示例脚本 -
我希望它对其他人有帮助
And got the solution using autoit, here is the sample script -
I hope it helps others
首先,我必须创建一个小类来找出哪些窗口打开,并将它们作为窗口字典返回。
在 Selenium 页面代码中,我单击按钮启动下载窗口并进行短暂的等待。 (这在代码中没有显示)
然后我使用下面的代码查找所有打开的窗口
切换到下载窗口(不同浏览器的窗口名称不同。请注意!)
输入文件的路径
按 Enter
键下载窗口应该关闭,因此我们切换回浏览器窗口(在本例中为 Firefox)。
这有几个问题,因为窗口标题根据所使用的浏览器而不同,因此需要考虑到这一点一个完整的解决方案。此外,当执行这部分代码时,不要将任何其他窗口带到前台,因为该窗口将接收“SendKeys”而不是所需的窗口。
First of all I had to create a small class to find out which windows were open and return them as a dictionary of windows.
In the Selenium page code I click on the button to launch the download window and put in a short wait. (This is not shown in the code)
Then I use the code below to find all open windows
Switch to the download window (the name of the window is different across browsers. Be Aware!)
Type in the path for the file
Press Enter
The download window should close so we switch back to the browser window (in this case Firefox)
There are a couple of issues with this as the window titles are different depending on which browser is being used, so this will need to be taken into account for a complete solution. In addition, when this section of code is executing do not bring any other windows to the foreground as this window will receive the 'SendKeys' rather than the required window.