attach_file isn't working the right way with capybara-webkit

回眸只為那壹抹淺笑 提交于 2019-12-11 12:57:39

问题


I'm trying to attach some files to this input:

<input type="file" name="image" multiple="" accept="image/*">

My code, that is working when I use selenium driver, is:

attach_file('image', File.absolute_path('../pictures/pic1.JPG'))
attach_file('image', File.absolute_path('../pictures/pic2.JPG'))
attach_file('image', File.absolute_path('../pictures/pic3.JPG'))

The problems come when I use capybara-webkit: as the input is hidden and some elements overlaps it, I need to change some css properties:

page.execute_script("$('input[name=image]').css('opacity','1')")
page.execute_script("$('input[name=image]').css('position','fixed')")
page.execute_script("$('input[name=image]').css('top','620px')")

And even if the test passes, the pictures aren't uploading the right way. If I use page.save_screenshot('after_upload.png') to see what's happening:

Expected result (and result when using selenium driver) ->

Actual result when using capybara-webkit ->


回答1:


I just found a "fix": put a sleep(3) after each image upload!



来源:https://stackoverflow.com/questions/34022916/attach-file-isnt-working-the-right-way-with-capybara-webkit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!