【发布时间】:2018-05-04 06:59:13
【问题描述】:
我正在尝试使用用 Ruby 编写的机器人上传文件。它失败了,但我认为我的合成器很好。我想最近升级的 Firefox 让我无法完成这项工作。请问你有什么想法吗?
我使用这些资源来编写我的代码:
https://saucelabs.com/resources/articles/best-practices-tips-selenium-file-upload
http://elementalselenium.com/tips/1-upload-a-file
我在这里得到了最后一个版本的 selenium:
https://rubygems.org/gems/selenium-webdriver/versions/2.53.0?locale=fr
我在这里得到了最新版本的 geckodriver:
https://rubygems.org/gems/geckodriver-helper/versions/0.0.3
但它不起作用:WebDriverError@chrome://marionnette/content/error.js:235:5 找不到文件
我在本地模式下使用 wordpress 和 local by flywheel。 火狐量子57.0 64位
这是我的小代码:
require 'selenium-webdriver'
require 'rspec/expectations'
include RSpec::Matchers
def setup
@driver = Selenium::WebDriver.for :firefox
end
def teardown
@driver.quit
end
def run
setup
yield
teardown
end
run do
@driver.get "http://mywebsite.dev/wp-admin/profile.php"
inputlogin = @driver.find_element :id => "user_login"
inputpwd = @driver.find_element :id => "user_pass"
inputlogin.send_keys "mylogin"
inputpwd.send_keys "mypwd"
@driver.find_element(:id, "wp-submit").click
@driver.get "http://mywebsite.dev"
element = @driver.find_element(:id, 'uploadInput1')
element.send_keys "C:\\path\\image.jpg"
# @driver.find_element(id: 'btn-submit').click
puts "Successful on #{@driver.title}"
end
由于它不起作用,我正在寻找另一种上传文件的方法,因此我尝试使用 AutoIT,但失败了……这是一个示例。
http://www.maisasolutions.com/blog/How-to-upload-images-using-selenium-webdriver-with-ruby
此外,此解决方案非常繁重(下载、安装、不可复制等),并且似乎不是正确的代码。
感谢您的帮助。
【问题讨论】:
标签: ruby wordpress selenium file-upload upload