2

在包含带有选择文件输入的表单的网页上工作,如以下代码段所示:

<form ... >
<div class="form__wrap">
  <ul class="form__list">
    Import: 
    <label for="fileUploadInput" class="btn mediaChoose inline" id="fileUpload">Choose File</label>
    <input class="mediaFile" id="fileUploadInput" name="file" type="file" />
  </ul>
</div>
...
</form>

使用 Watir WebDriver,以下返回 true:

puts file_field(:id => "fileUploadInput").exists?

但是,下面的 file_field 调用会在 Chrome 上导致以下错误(适用于 Firefox 和 IE):

file_field(:id => "fileUploadInput").set(pathtofile)

Element is not clickable at point (695, 314). Other element would receive the click:
<label for="fileUploadInput" class="btn mediaChooseinline" id="fileUpload">...</label>
4

2 回答 2

3

My guess is that you are driving Chrome, since I have seen errors like that before. The error message is saying that you are trying to click file upload element, but label is displayed over it, so clicking the desired coordinates on the screen will click the label instead of file upload element. Chrome gets confused at that point and refuses to click.

To make sure that is the problem, try the same code with another browser, Fireofox for example. Experience has shown that Firefox does not care if another element will receive the click.

于 2013-03-08T08:39:12.033 回答
0

我尝试了一个类似于您发布的表单的缩小表单,它在 Chrome 和 Firefox 中对我有用。这是在 Windows 机器上测试的。我确实注意到 FireFox 和 Chrome 对路径目录有不同的语法。

HTML -

<!DOCTYPE html>
<html>
<body>

<form action="demo_form.asp">
Import:
<label for="fileUploadInput" class="btn mediaChoose inline" id="fileUpload" >test</label>
<input class="mediaFile" id="fileUploadInput" name="file" type="file" />

</form>

</body>
</html>

测试代码

require 'watir-webdriver'

browser = Watir::Browser.new :firefox
browser.goto "C:\\Users\\mike\\ruby\\chrome1.html"

puts browser.file_field(:id => "fileUploadInput").exists?
#browser.file_field(:id => "fileUploadInput").set("c:\\Windows\\")  #chrome
browser.file_field(:id => "fileUploadInput").set("c:\\Windows\\..")  #firefox
browser.file_field(:id => "fileUploadInput").click
于 2013-03-07T23:45:05.490 回答