Watir-Webdriver:在 Firefox 上上传文件无法正常工作
使用此代码我无法将文件正确上传到网站。
browser.form(:index, 2).file_field(:name, "filedata").set(""+folderName+"/iTunesArtwork")
代码运行后,它显示正在通过显示旋转轮进行上传,但它实际上从未上传,并且轮子只是不断旋转。如果我自己上传的话,虽然上传得很好。
这是 html 的链接: http://f.cl.ly/items/3v3o1p1g0t2S1q3q3Q1h/Text%202011.09.03%2011:40:06%20PM.html
如您所见,html位于表单标签中。如果我尝试在不先通过表单的情况下访问 file_field ,则会出现错误,指出元素无法交互,因为它不可见。有人知道发生了什么事吗?
Using this code I cannot get a file to upload correctly to the website.
browser.form(:index, 2).file_field(:name, "filedata").set(""+folderName+"/iTunesArtwork")
Once the code is run it shows that it's uploading by displaying a spinning wheel but it never actually uploads and the wheel just keeps spinning. If I upload it on my own though it uploads fine.
Here's a link for the html:
http://f.cl.ly/items/3v3o1p1g0t2S1q3q3Q1h/Text%202011.09.03%2011:40:06%20PM.html
As you can see the html is in a form tag. If I try to access the file_field without going through the form first it will give me an error saying element can't be interacted with because it's not visible. Anyone have a clue what's going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您上传的本地文件不得在本地存在。
我已将您的 HTML 上传到:http://dl.dropbox.com/u/18859962/ uploader.html
我尝试了以下操作:
请针对此托管 html 文件运行您的脚本并返回报告。
另外,如果本地文件不存在,您应该引发异常,以便消除该错误。
Your local file you are uploading mustn't exist locally.
I have uploaded your HTML to: http://dl.dropbox.com/u/18859962/uploader.html
I tried this:
Please run your script against this hosted html file and report back.
Also, you should raise an exception if the local file doesn't exist, so that eliminates that error.
在我开始为其提供文件的绝对路径之前,我无法让 file_field.set 工作。
我的代码看起来像这样:
希望这有帮助!
I wasn't able to get file_field.set to work until I started giving it an absolute path to the file.
My code looks something like:
Hope this helps!
就你问题的这一部分而言:
最可能的答案是,DOM 中可能存在另一个具有相同名称且当前对用户不可见的输入字段。由于无法查看整个页面并查看所有 HTML,我不能肯定地说,但当我尝试与具有相同名称或文本的控件进行交互时,该错误是典型的,但目前隐藏在视图中。在页面代码中搜索我正在使用的名称或文本通常会发现其他元素。改变我处理问题的方式(通过指定一个唯一的容器,或者添加
:index
值以及现有标识符,然后将允许您获取元素的“正确”实例 。您可以改用
:id
来标识字段(它有一个),然后看看这是否有效,而无需先指定外部(表单)容器元素,通常首选按 ID 选择 因为如果该值有效,则该值在页面上应该是唯一的然而,这并没有解决您问题的“为什么不上传”方面,我怀疑这是您需要帮助的真正问题,但它确实解决了您问题的这一方面
,但没有 。由于我自己能够与该网站进行交互,所以很难说为什么它会这样(如果该网站是 itunes,您应该检查他们的服务条款中关于使用自动化访问该网站的内容)。
In terms of this part of your question:
The most likely answer is that there may be another input field in the DOM that has the same name and is not currently visible to the user. Without being able to look at the entire page and see all the HTML, I can't say for sure, but that error is typical of when I've tried to interact with controls that had the same name or text as others, but were currently hidden from view. searching the page code for the name or text I was using would usually discover the other element. Changing how I was addressing things (either by specifying a unique container as you are doing, or adding an
:index
value along with the existing identifier will then allow you to get the 'right' instance of the element.You could switch to using
:id
to identify the field (it has one), and see if that works without having to specify the outer (form) container element first. Selecting by ID is generally preferred anyway as the value should be unique on the page if it's valid HTML.That doesn't address the 'why doesn't it upload' aspect of your question however, which I suspect is the real problem you need help with. but it does address that aspect of your question.
As to the rest, without being able to interact with the site myself, it's difficult to say why it is behaving the way it is. (and if the site is itunes, you should check what their terms of service has to say about using automation to access the site)