Reputation:
I'm writing Test Cases using Robot Framework and Selenium for my Web application. I tried to Upload a file, but I can't its failing.
My Code is
*** Variables ***
${TVAURL} http://localhost:1500/
${Browser} Firefox
TC_01: Enter into the application
[Documentation] Enter into the application to upload a file
Open Browser ${TVAURL} ${Browser}
maximize browser window
Choose File ........
HTML File:
<!DOCTYPE html>
<html>
<head>
<title>Upload File</title>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
I need to know how to use this Choose File
for this file upload test. I don't know how to do this. I need to upload a file automatically without any third party tools like Autoit, etc.,
I referred the following http://robotframework.org/Selenium2Library/Selenium2Library.html#Choose%20File
Moreover I referred the following questions too
But I can't get any solutions. Kindly assist me how to do this using Robot Framework, Selenium in Pycharm Studio.
Reply for Answer #1: @demouser123
Still I'm having issue, here with I have attached the Screen shot
It always opens the Desktop, and fails. Kindly assist me.
I trided the following code
*** Variables ***
${PO_AddShell} //*[@id="fileToUpload"]
click button ${PO_AddShell}
Choose File ${PO_AddShell} E://Project/Publish/SampleTest.1500/rose.jpg
Upvotes: 2
Views: 42956
Reputation: 1
The syntax to use the Choose File keyword
Choose File Locator File_name
This keyword work fine for locator type=file
so try to use locator =//input[@type="file"]
Upvotes: 0
Reputation: 1
You should not use
click button ${PO_AddShell}
Just use choose file without clicking
Upvotes: 0
Reputation: 63
using autoit library in robotframework, you can upload a file into application. This solution works even the system is locked.
Input Filename and click send in Window dialog
run keyword if '${Browser}' == 'Chrome' File upload in Chrome browser
... ELSE IF '${Browser}' == 'Firefox' File upload in Firefox browser
File upload in Chrome browser
control focus [CLASS:#32770; TITLE:Open] ${EMPTY} [CLASSNN:Edit1]
control send [CLASS:#32770; TITLE:Open] ${EMPTY} [CLASSNN:Edit1] C:\\File_Upload\\Test_Upload
control click [CLASS:#32770; TITLE:Open] ${EMPTY} &Open
File upload in Firefox browser
control focus File Upload ${EMPTY} [CLASSNN:Edit1]
control send File Upload ${EMPTY} [CLASSNN:Edit1] C:\\File_Upload\\Test_Upload
control click File Upload ${EMPTY} &Open
Upvotes: 0
Reputation: 1511
Prerequisite for running below script :
Install Sikulix on your machine from this SikuliX ,this is easy to install and install robotframework-SikuliLibrary . You can explore the documentation if you want some more options SikuliX documentation. Capture the images like download path/filename using some snipping tool and update the name in the following script.
*** Settings ***
Library Selenium2Library
Library SikuliLibrary
*** Test cases ***
Login to Browser with download preferences
[Documentation] This one is without specifying download location
Open Browser https://www.docdroid.net/ Chrome
Click Element id=selectFiles
Sleep 5
SikuliLibrary.Click /images/download.PNG
SikuliLibrary.Click /images/file.PNG
SikuliLibrary.Click /images/open.PNG
If you want to specify download location , go with below script
*** Settings ***
Library Selenium2Library
Library SikuliLibrary
*** Test cases ***
Login to Browser with download preferences
[Documentation] You can specify your download location
Open Browser https://www.docdroid.net/ Chrome
Click Element id=selectFiles
Sleep 5
SikuliLibrary.Input Text /images/file_path.PNG C:\\Users\\Madhu\\Downloads
Press Special Key ENTER
#SikuliLibrary.Click /images/download.PNG
SikuliLibrary.Click /images/file.PNG
SikuliLibrary.Click /images/open.PNG
Upvotes: 0
Reputation: 4264
As per the documentation given in the Selenium2library, the syntax to use use the Choose File
keyword is
Choose File Locator File_name
For a dialog or input that WebDriver can interact with the example would do something like this
Choose File id=fileToUpload C://Downloads/Demo/Abc.txt
Here C://Downloads/Demo/Abc.txt
is the location on the system where the file is kept. Change this to your own file location.
Also, I remember this solution also, which ultimately worked for me too - SO Post about uploading from a Windows directory. You can also try this one.
Upvotes: 3