Search code examples
rubyphantomjswatirwatir-webdriver

Upload file with watir and phantomjs on OSX


I'm trying to upload a picture with watir and phantomjs but it's failed.

Html code is:

<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>

i tried

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)

and

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

But it doesn't work, i have a Net::ReadTimeout error. Where am I wrong? thx


Solution

  • Yes this is a known phantomjs bug: https://github.com/detro/ghostdriver/issues/183

    Phantomjs driver has not been actively maintained for years. The Selenium team generally recommends against its use for testing.