I was writing a script to upload a file to a website in Watir, It is a memorandum because I solved the problem that it was difficult to find information in the old environment.
CentOS Linux 7 Ruby 2.0.0p648 Specifications gem is Watir The browser uses Firefox, but other browsers such as Chrome can also be used.
I want to upload a file to a website by starting an automatic script using Watir. On the upload screen, press the button called Select file, and when the file selection screen appears, select a file from it and upload it.
The behavior of selecting a file from the upload screen is not working. When the OS standard file selection screen opens, the operation of the script does not reach whether it operates outside the browser.
browser.execute_script("
document.dispatchEvent( new KeyboardEvent( 'keydown', { keyCode: 86 , ctrlKey: true , key: 'V' }) );
")
(Reference: https://ameblo.jp/personwritep/entry-12456996738.html) I tried such things as, but it does not perform operations such as going to read the target file.
The screen for uploading files is below, and you can press the Select file
button.
Then, the following OS standard file selection screen appears, and it is designed to upload files from there.
When operating by hand, you can select the file after pressing the Select file
button, or you can upload the file by dragging and dropping.
As a result, it's done.
$browser.file_field(:id, //).set("filepath\/...\/file.png ")
https://stackoverflow.com/questions/15163816/automating-a-file-upload-with-watir-in-chrome-on-osx https://www.rubydoc.info/gems/watir/1.8.1/Watir%2FContainer:file_field
No Watir.
Recommended Posts