3

I am using robotframework ,selenium2Library, selenium2 and python27 to test web program. It need to upload a file in my web program. I use Choose File to give file path value to input filed. But it is not work for firefox and it works fine in chrome. When I upload file manually in firefox, it works. It is a register page. Javascript code told that file upload field is empty when the form is trying to submit, since selenium seems did not give the file path to the value of file upload field. And other input fields all have been input values, no matter fields before this file upload filed nor those fields after it. Does anyone know how to solve this problem or is there any alternative solutions?

Nick Dong
  • 3,638
  • 8
  • 47
  • 84

1 Answers1

1

I've had success having selenium type the file path into the webpage directly. It works most of the time, but the site I use it on is being constantly updated and one week you can type a file path, the next week you can't, the following week you can again.

I say this as a precaution that this may not be the ultimate solution, but there are instances where it works. Your particular case may be able to use this method.

driver.find_element_by_name("FILE_UPLOAD_ELEMENT_NAME").send_keys(os.path.expanduser("~/PATH_TO_FILE"))

Feel free to find element by any other characteristic and replace the all caps parts be appropriate for your use.

ExperimentsWithCode
  • 1,174
  • 4
  • 14
  • 30
  • I am using robotframework and seleinum2library. I am a newbie in this field. But I think choose file should do same work either, which is just `send_keys`. I dont know where to use the code, which you gave me above. and thanks – Nick Dong Nov 01 '13 at 10:55