0
votes

I am trying to upload file using choose file robot framework keyword. When I execute the test it runs successfully but the file is not uploaded.

Here is my HTML

enter image description here

I would like to click on Upload Study button to browse the file. I tried following :

choose file  xpath=(//button[contains(.,"Upload Study")])  Study_File.csv

But it is not uploading the file. Is it because input type=file is not present in the xpath I used? If so how should I create the xpath?

2
Did you try to use locator for input that is few lines below your button? - JaPyR
Yes I tried. But its not upload the file. - Sachetan
After your manually select file for which html element attributes are changed? - JaPyR
What was the error when you tried Choose File on the <input> tag? Selenium is able to upload files only through it (it sets the filename to its property). - Todor Minakov
JaPayR - don't see change in any html element attibute - Sachetan

2 Answers

0
votes

The choose file keyword requires that you give the locator to an input element, not a button. From the keyword documentation:

Inputs the file_path into file input field locator.

You probably want a locator like id:fileUploader

0
votes

If you have already tried using the <input> element as the locator, then my next guess would be that it can't find the file you're trying to upload. You have referenced the file as simply 'Study_File.csv', which suggests it's in the same directory as the test file. If it's located elsewhere then you need to provide a path to it relative to the location of your test file.