[英]Unable to upload a file with Selenium - Ruby
I am trying to upload a file using a bot written in Ruby. 我正在尝试使用Ruby编写的机器人上传文件。 It failed but I think my synthax to be good. 它失败了,但我认为我的合奏很好。 I suppose that the recent upgrade of Firefox unabled me to do the job. 我想最近的Firefox升级使我无法完成这项工作。 Have you got an idea please ? 请问您有个主意吗?
I used these resources to do my code : 我使用这些资源来编写代码:
https://saucelabs.com/resources/articles/best-practices-tips-selenium-file-upload https://saucelabs.com/resources/articles/best-practices-tips-selenium-file-upload
http://elementalselenium.com/tips/1-upload-a-file http://elementalselenium.com/tips/1-upload-a-file
I got the last version of selenium here : 我在这里得到了硒的最新版本:
https://rubygems.org/gems/selenium-webdriver/versions/2.53.0?locale=fr https://rubygems.org/gems/selenium-webdriver/versions/2.53.0?locale=fr
I got the last version of geckodriver here : 我在这里获得了geckodriver的最新版本:
https://rubygems.org/gems/geckodriver-helper/versions/0.0.3 https://rubygems.org/gems/geckodriver-helper/versions/0.0.3
But it didn't work : WebDriverError@chrome://marionnette/content/error.js:235:5 File not found 但这没用:WebDriverError @ chrome://marionnette/content/error.js:235:5找不到文件
I am using wordpress in local mode with local by flywheel. 我在飞轮本地模式下在本地模式下使用wordpress。 Firefox Quantum 57.0 64bits Firefox Quantum 57.0 64位
Here is my little code : 这是我的小代码:
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
As it didn't work, I was looking for an other way to upload my file so I tried using AutoIT but I failed... Here is an example. 由于无法正常工作,我在寻找其他上传文件的方法,因此尝试使用AutoIT,但失败了……这是一个示例。
http://www.maisasolutions.com/blog/How-to-upload-images-using-selenium-webdriver-with-ruby http://www.maisasolutions.com/blog/How-to-upload-images-using-selenium-webdriver-with-ruby
Moreover, this solution is very heavy (downloads, installations, non reproductability etc.) and don't seems to be proper code. 而且,此解决方案非常繁琐(下载,安装,不可复制等),并且似乎不是正确的代码。
Thank you for your help. 谢谢您的帮助。
Find a file field on the page and attach a file given its path. 在页面上找到文件字段,并根据路径添加文件。 The file field can be found via its name, id or label text. 可以通过名称,ID或标签文本找到文件字段。
page.attach_file(locator, '/path/to/file.png')
Here, locator will be CSS
id or class of file upload path. 在这里,定位器将是CSS
ID或文件上传路径的类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.