0
votes

I am developing a scenario where a file is uplodaded using the choose file robot framework keyword. The test runs and when the choose file executes, it hits the locator for the <input type="file"> element, the UI shows a red box at the bottom of the page (see attachment), but the file is not uploaded.

enter image description here

Im not sure if the UI doesn't know how to handle the upload, or if there is an error in my code:

choose file  xpath=/html/body/div/div/div/div[2]/div/div/div/div/div/div/div/div/div[1]/div[1]/div[2]/div/span  ${dataDir}studentSAT.csv

The ${dataDir} variable contains the OS full path to the file, and the file is at that location. As a point of validation, I tried changing the filename to one that is not present, and robot throws an error stating data not available.

Has anyone encountered this before?

2
I don't see an attachment. - Bryan Oakley
Thanks Bryan, realized that a few minutes ago! Just updated with a screenshot. - Charles Ramsell
Which browser / driver you are using exatcly? I had luck with Choose File keyword with newest Chrome Webdriver and Chrome 57.x. - ponkape
On my local system (CentOS 7) I am using the Native FF browser and associated drivers. I have tried using Chrome Webdriver and Chrome 59.x, but those don't want to work at all, and I've gotten farther with the FF products. On the AWS server (Ubuntu) I am using the Mozilla Geckodriver as the tests operate headlessly using XVFB. I haven't tried them on that platform yet, as I am still in the design/debug phase of development. - Charles Ramsell
And you're sure that ${dataDir} contains an ending path delimiter? E.g., it equals something like: /home/testuser/datadir/ - ? Otherwise, you're referencing something like /home/testuser/datadirstudentSAT.csv - Greg M

2 Answers

0
votes

I encountered the same issue before, i tried multiple things such as Simulating Keyword Actions and entering file path in file upload dialogue box, Using Choose File Keyword, AutoIT Library for Robot Framework.

1) If you intend to run your tests on local machine, i would say use pyautogui (for Python) and Robot Class (For Java) and use Tab/Enter/Key Press methods and to do the job.

2) If you intend to run your test on Remote Machine aka VMs, Set up AutoIT on RemoteMachine/VM and use AutoIT library For Robot Framework.

0
votes

After some additional digging, it turns out that in this case, the <input type=file> element was not visible. The red box at the bottom left was the browsers attempt at dealing with a file being passed to it with no known way of interacting with the element that wasn't visible. Changing the element display properties from 'style.display = "none"` to 'style.display = "block"' allowed the element to be visible on the screen, and be selected.

I implemented an 'execute javascript' keyword step before attempting to pass the .csv file, and it works beautifully now.

Code:

execute javascript window.frames[0]; document.querySelector( "input[name='file-uploader']" ).style.display = "block";

enter image description here