I need to automate the file upload feature in a web console and i am using selenium and java for this.
I tried multiple approaches but when i click on upload button and windows explorer gets opened, it stops there.
doesn't select any file...and gives error that there is no file..
I tried in firefox and chrome both but i am not able to solve this problem.
Then i also tried AutoIt tool. I downloaded it and made a script. trying to compile my script i am getting this error:
Code I'm using:
WebDriver driver = new FirefoxDriver();
driver.get("localhost:8080/page");
WebElement selectUploadApk = driver.findElement(By.id("id of upload button"));
selectUploadApk.click();
WebElement file = driver.findElement(By.xpath("//input[#type='file']"));
file .sendKeys("path of the file");
Error: Unable to execute upx.exe to compress stub file
File not found Exception
Please help
Thanx in advance
Megha
You don't need to click on the field to open the dialogue box.
Opening the dialogue box is what is 'breaking' your test.
Just send the keys directly to the input element, as you are, and then click on which ever button is the 'upload' button.
driver.findElement(By.xpath("//input[#type='file']")).sendKeys("/path/to/file");
driver.findElement(By.id("id of upload button")).click();
Related
I ran webdriver, everything was great, until OS file browser pop-ups and webdriver can't interact with it so it can't automatically choose the file on file browser.
So how can I choose the file on file browser automatically?
Did you click an upload button?
Instead you'll want to find the input element with the type 'file'. Once you've located this, perform a send keys command with the file location.
E.g.
driver.findElement(By.xpath("//input[#type='file']")).sendKeys("File Location") ;
I have created testing automated script for a webpage of my desktop application. so it runs fine manually from eclipse. I am using selenium web driver and java.
Now I want to create GUI/Easy interface where I can get input from user And RUN my file on button click,so when tester gives input and tap on button ,we see out put fro my script on the samepage
I have exported all functions as Runnable JAR , So now I need to know how can I call and run these runnable jar from html page?on click. Is there any easy way for this?
Please help me
My requirement, after cliking on the Export button, os save dialog appears where i need to select the download path and save it. Also i need to wait till the file download complete to make sure that the file is downloaded successfully.
I have used Selenium Webdriver till cliking on the Export button, I have handled the os save dialog for firefox browser by setting the firefox profile preferences to auto downlaod the file to the provided path. File starts downloading, but am stuck in verifying the status of file download. My file size varies and hence i cant wait for some time and check in the downlaod path, if the file exists. Also i will be not knowing the file name while exporting and #href attribute of Export button doesnot provide any url info.
can i use AutoIT? as am working on Windows platform.
I need to implement the above in IE, Chrome browsers as well. Pls let me know the possible solutions to handle the os save dialog and to verify the status of file download.
See if this helps: http://imobiliarerolabs.tumblr.com/post/64859016557/how-to-use-sikuli-when-automating-tests-with-selenium
It's Sikuli and can be used with Selenium.
I have an "Export" button so after click on it the .csv file with some data is downloaded.
Is there a way to test in Selenium2 the following points:
The file is downloaded after click on the "Export" button
The downloaded file is a .csv format file.
File data is correct. (There are three columns, let them be Column1, Column2, Column3 )
I will really appreciate all of the suggestions on how to do the tings above using Java.
Actually, It is not possible to handle the Native windows using the selenium web driver. You can go for the third party tool like AutoIT to resolve this kind of issue.
For more info on AutoIT Tutorial and this too.
In firefox also you can do the same thing.
Create one firefox profile
Change the firefox download setting as it should save files without asking about location to save
Launch the automation using that profile.
FirefoxProfile profile = new FirefoxProfile(profileDir);
driver=new FirefoxDriver(profile);
below you can see how to change firefox file download settings
And then by using by some programming language you can do remaining things
Checking format
Verification of content
Integrate Sikuli library in your test script. You can easily compare through snapshot.
I'm using Selenium 2.21.0 with Java 6. How do I use the Selenium WebDriver API to download a file on a web page? That is, there is a link that causes the download of an Excel file to start. I would like to know how to initiate that download, determine when its finished, and then figure out where the file got downloaded to on my local system.
Once you click on any link to download a file, it depends on browsers behaviour like
Chrome Behaviour: It will start downloading the file by default, as soon as the user click on the link of any file.
IE Behaviour: IE displays a bar at the bottom of the window and displays the option to Save or Cancel the file download.
FireFox Behaviour: This will display an dialog box window and displays the option to Save or Cancel the file download.
So this can be achieved with the help of FireFox Profile.
And Before downloading any file you have to pass the MIME type of the file to FireFox Profile.
Some of the commonly used MIME types are:
Text File (.txt) – text/plain
PDF File (.pdf) – application/pdf
CSV File (.csv) – text/csv
MS Excel File (.xlsx) – application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
MS word File (.docx) – application/vnd.openxmlformats-officedocument.wordprocessingml.document
HERE IS THE CODE:
import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
public class DownloadFiles {
public static void main(String[] args) throws InterruptedException {
//Create FireFox Profile object
FirefoxProfile p = new FirefoxProfile();
//Set Location to store files after downloading.
profile.setPreference("browser.download.folderList", 2);
//Set preference not to file confirmation dialogue
profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
"application/vnd.openxmlformats-
officedocument.spreadsheetml.sheet");
// Specify the local system path where to download
p.setPreference("browser.download.dir", "D:\\downloads");
// Pass Profile parameters in Firefox browser
FirefoxDriver driver = new FirefoxDriver(profile);
// Open APP to download application
driver.get("http://url");
// Click to download
driver.findElement(By.xpath("//html[#attribute='value']")).click();
Thread.sleep(5000);
driver.close();
Hope it will solve your queries. Happy coding.
I am specifically focusing of the Firefox browser you can use where the download option comes with pop up option when any download link is been click by the visitor. It is shows two buttons and two radio button that gives us the option of save and open the file directly without downloading it afterwards if we find the file is useful we can download it explicitly though the download icon on the above toolbar of the Firefox browser.
So you can perform the following steps
1) Clicking on the download link
WebDriver driver = new FirefoxDriver();
driver.findElement(By.linkText(“somelink”)).click();
The above code can help the WebDriver to identify the object and perform the action which is mentioned
2) Once the download link is clicked the firefox browser will pop up a download dialog box with multiple option
Like Save radio button, open radio button, ok button, cancel button inorder to use this
You can use the Robot class or the Keys in the WebDriver
Like
Robot r = new Robot();
r.KeyPress(KeyEvent.VK_TAB);
you can use as many time the above code to press the tab button
r.KeyRelease(KeyEvent.VK_TAB);
you have to release the pressed key
lastly perform the enter
r.KeyPress(KeyEvent.VK_ENTER);
That’s it it will help you to download the object when the download link is pressed
Hope it will help you