I am trying to write a java program that uses selenium to perform web actions. In the case of uploading a video there is a frame where the user clicks that brings up the File Explorer for Windows. I have not been able to find anything that will help me in getting the focus to the File Explorer to select a file. There is no "browse" on the page with a textbox for me to just send a filename to.
Here is what the page looks like:
I would try using Selenide because it has a pre-canned upload utility that might save you some time/effort. See the command .uploadFromClasspath in the docs. One of the project videos/pages shows a little more detail on how to do it.
I've not actually tried it, but if this works for you and you figure it out, please share.
What I have done in the past is to use the "Apache HttpUtils" class to simulate the upload action from my test. All you need is the upload URL, and the HTML page usually provides that. That might also work for you.
Related
I want to upload the picture so that I can access it in my project, I have used the sendKeys("path of the picture") but by using it no action is performed,
please guide me, how to use the window pop up to upload the picture or give some idea, how can I upload the picture:
WebElement Account_logo = adriver.findElement(By.xpath("//*[#id='step1']/div[1]/div/div/div/form/div[12]/div[1]/div/div/span/div[2]/div[2]"));
Account_logo.click();
Account_logo.sendKeys("C:/Users/romit/Desktop/LOGO.jpg");
When setting the file path in your Java IDE, use the proper escape character for the back-slash.
Account_logo.sendKeys("C:\\Users\\romit\\Desktop\\LOGO.jpg");
Hope it helps !
If you want to upload a file, without having 'input' element, please refer SO Post
I have created an application in JSwing that has a button that I want to open the user manual (which is a html file) in a browser. I can successfully open the entire webpage, but I want to link to certain anchors in the document. For example I am trying to use this code:
URI uri = new URI("c:/Giggafriggin/user_manual/user_manual.html#h1_3");
Desktop.getDesktop().browse(uri);
But this causes an error, claiming the file cannot be found. But if leave off "#h1_3" it opens the page in a browser without a problem. The anchors work when i enter them into the browser manually. Any ideas?
You -could- have that linking to another html page which goes to the end uri. Unfortunately, Java is not a web browser.
Looks like this is a known issue you wouldn't run into if you were using HTTP instead of a local file.
One easy fix is simply to point to a version of the that's already online instead of on disk.
If you can't assume the content is available online, you could always spin up an embedded HTTP server like jetty inside your application and point to that instead.
I'm trying to code in a download in my java application. Basically, the user inputs their personal information, which is sent through file i/o to a text document. Then the next step is to have a series of buttons or links that corresponds to a certain download. For instance, button1=file1, button2=file2, and so on. I need it to download a picture. Is this possible through a dialog box? I'm running the application through a website. Any help is appreciated!
You can download a file from a URL using URLConnection. You can have your dialog box display the choices then choose a URL depending on what button they pressed, and use the URLConnection (via .connect() and .getInputStream()) to read the data, which you can then write out to a file or do whatever you want with.
You say you are running it through a web site, so I assume this is an applet. Bear in mind that if it is an unsigned applet you can only download files from the server that the applet is on. If you need to download from anywhere, you will need to sign your applet, or use something that isn't an applet.
Also, since you are running it through a web site, if it's appropriate perhaps a different approach is to just redirect the user to the URL of the file and let their browser take care of the download.
I have to automate a case in which I have to download an excel file using selenium ide.I have done this in firefox by using custom profile feature which automatically download file and save it into a user defined folder. To do the same in Internet explorer, is there any thing in IE like custom profile and preferences? how do I prompt IE to automatically download a file..I am using java for automation..Kindly help..
No, you can't do it easily in IE, there's no profile to configure.
That said, you can try:
downloading the file directly using this (or any other similar WebDriver-friendly tool), if you can. That will totally cut IE out of the process.
see How to download and save a file from Internet using Java? about the same thing, just generic Java and not WebDriver.
if everything fails, you can try blindly pressing Enter after clicking the download, Robot helps with this. But you can't really specify the folder.
We're building an analytics portal, and needless to say, a top feature is the ability to export statistics to excel. My question is - Does Selenium provide the ability to detect the generation of Excel files (upon clicking the icon within the portal)?
At this stage, just the presence (or absence) suffices. I don't need to delve into the excel file contents (yet).
More information - Here is a screenshot of the excel file that is generated...
This notification seems outside Selenium's purview
The file download dialogs are part of the Windows Component Object Model (COM) and not the Browser, thus selenium won't be able to work with it. One of the best ways to handle it with a tool that can interact with the COM, such as AutoIt (mentioned in a comment above).
See this answer that contains example script to do what you want: how to handle IE Download dialog with VB Script? but instead of invoking AutoIt from VBScript you would invoke it with the code running selenium (but it will have to be on the local machine).