在 OSX 上使用 watir 和 phantomjs 上传文件

Upload file with watir and phantomjs on OSX

我正在尝试使用 watir 和 phantomjs 上传图片,但失败了。

Html代码为:

<div class="qq-uploader">
        <div class="qq-upload-drop-area" style="display: none;">
            <span>Drop files here to upload</span>
        </div>
        <div class="qq-upload-button" style="position: relative; overflow: hidden; direction: ltr;">
            <div>Click or Drop for upload images</div>
            <input multiple="multiple" type="file" name="qqfile">
        </div>
        <span class="qq-drop-processing">
            <span>Processing dropped files...</span>
            <span class="qq-drop-processing-spinner"></span>
        </span>
        <ul class="qq-upload-list"></ul>
    </div>
</div>

我试过了

require 'phantomjs'
require 'watir'
require 'watir-webdriver'
Selenium::WebDriver::PhantomJS.path = '/phantomjs/bin/phantomjs'

b = Watir::Browser.new(:phantomjs)
b.goto("http://website.com")
b.text_field(:name => /title/).set 'My title'
b.div(:id => "restricted-fine-uploader").fire_event :click
file = "/Users/Tom/Pictures/image.jpg"
b.file_field.set(file)

b.div(:id => "restricted-fine-uploader").fire_event :click
file = "/Users/Tom/Pictures/image.jpg"
b.file_field(:name => "qqfile").set(file)

但是它不起作用,我有一个 Net::ReadTimeout 错误。我哪里错了?谢谢

是的,这是一个已知的 phantomjs 错误:https://github.com/detro/ghostdriver/issues/183

Phantomjs 驱动程序多年来一直没有得到积极维护。 Selenium 团队通常不建议将其用于测试。