简体   繁体   中英

File Upload in Robot Framework f

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    diego.mg.umh@gmail.com
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.-

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM