Uploading files using ruby / Selenium

回眸只為那壹抹淺笑 提交于 2019-12-06 21:28:28

As I have no your code, assume we are testing https://encodable.com/uploaddemo/

@driver.navigate.to "https://encodable.com/uploaddemo/"
element = @driver.find_element(:css, 'input[type=file]')
element.send_keys   "/full/path/to/file.jpg"
@driver.find_element(:css, 'input[type=button]').click

So, you should send the full path to the input field and press the "submit" button

M-Ria

I know this is coming a year late but I just started writing a script in Selenium/Ruby and it took me some time to figure it out so wanted to post my solution (and it was as simple as 2 lines!):

*the first line inserts the file path WITHOUT clicking on the browse button, key is to separate directories using double back slashes \\

*the second line clicks on the Save/Upload button

driver.find_element(id: "Document_upload").send_keys("C:\\Users\\me\\Desktop\\my_file.txt")
driver.find_element(id: "save").click
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!