1

I'm trying to make a test for the Upload file button of a web using robotframework but I can't find the way to do it.

Concretely, I'm using this web as a example:

http://www.zamzar.com/

And this is the properties of the upload button:

<input id="inputFile" class="bodyBig" type="file" name="file_1" size="12" 
style="position: absolute; display: block; opacity: 0; z-index: 0;">

As I saw in the documentation, I'm using the Choose File but I get stucked in the Windows pop-up, it opens but file is not selected:

Windows pop-up

My testcase looks like this:

*** Settings ***
Suite Setup       Test Setup Open Browser
Suite Teardown    Test Teardown Close Browser
Resource          SeleniumKeywords.tsv

*** Test Cases ***
Select file typing path
File Should Exist    C:${/}Users${/}MADI${/}Desktop${/}image.bmp
Wait Until Page Contains Element    id=inputFile
Choose File    id=inputFile    C:${/}Users${/}MADI${/}Desktop${/}image.bmp
Select From List    toExtensionSel    jpg
Input Text    toEmail    [email protected]
Click Button    uploadButton
Sleep    10

The file exists and it's in the correct location, do you know what do I need to change in order to get the file uploaded?

Thank you in advance, best regards.-

2
  • What do you mean by "get stucked in the Windows pop-up"? Are you saying the file dialog appears but you can't interact with it? Or are you expecting it to appear but it is not? Commented May 21, 2017 at 22:19
  • I meant that file dialog appears but I can't interact with it, maybe this image helps a bit: i.imgur.com/ehrRQQm.gif Commented May 22, 2017 at 7:31

2 Answers 2

1

When you are clicking on "Choose File" button, a window is displayed which we can automate. So we have a couple of methods to overcome this issue.

  1. Use AutoIt tool which can automate windows application. Learn about that and apply it there.
  2. Use javascript executor. As you can see that we can drag and drop any file just below the choose file. Examine the DOM what was happening when you drag and drop the file there. Place a file at your project level and check how can we apply there.

Let me know if there is any issue.

Sign up to request clarification or add additional context in comments.

Comments

1

For uploading a file, you no need to worry about the windows popup. the Windows popup only appears when you upload a file manually.

So, when you are simulating the same via automation code use the following code format

choose file  ${xpath}  ${absolute_file_path}

Where Choose file is the Keyword which you have imported from selenium2libary, ${xpath} is the xpath of the upload file element in your case it is

xpath=//input[@id='inputFile'] 

And ${absolute_file_path} is the file path with file name from where you want to upload the file.

${absolute_file_path}  C:\Users\MADI\Desktop\image.bmp 

If you are using separate resource file to define the variable used in your code.

1 Comment

Your first code examples seems to have a copy/paste error. The same text is repeated ("choose file ${xpath} ${absolute_file_path}choose file...")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.