How to handle FileUpload using selenium-Webdriver - java

//div[#id='upload_button']
driver.findElement(By.xpath("//div[#id='upload_button']")).click();
driver.findElement(By.xpath("//div[#id='upload_button']")).sendKeys("V://Images//CSV/text.csv");
I have a upload button in my browser
written a script that will click the button and send the mentioned file from given path
Here it is selecting the Upload button and file explorer opening
Not opening path, to send the csv file

If //input[#type='file'] is present at least one time in the HTML-DOM, the you can directly send the keys, you do not need to
Click on upload button
Select file using explorer
and upload the file.
This feature was introduced in one of the Selenium 3 versions.
Effective code:
driver.findElement(By.xpath("//input[#type='file']")).sendKeys("V://Images//CSV/text.csv");
I would recommend that use explicit wait for more stability.

driver.findElemnt(By.xpath("//input[#type='file'])).sendKeys(" give source file path");

Related

Open file dialog using in Java selenium test case

In my angular application, I am writing test cases using selenium.
In one of the test suite, I have a scenario where on click of a button, I need to open a Windows FileInput dialog and select a file that is passed and read the data in the file.
How can I achieve this.
I am using like this but nothing happens. How can I achieve this?
driver = Chrome webdriver;
element = driver.find_element_by_id("fileUpload")
element.send_keys("myfile.txt")
Uploading file with Selenium is done not the same way human user does.
With Selenium you should bot click on dialog, open OS browsing dialog, select file and click "upload" button.
With Selenium uploaded file should be sent to a special element presented on the page.
This is not a visible element.
It can be located by following XPath: "//input[#type='file']". The same with CSS Selector "input[type='file']".
Full absolute path to uploaded file should be sent to that element.
Like the following:
driver.findElement(By.xpath("//input[#type='file']")).sendKeys("C:/path/to/file.extension");

Is there anyway I can open a PDF from UI made from Angular/JS in Acrobat from one button click

I'm currently implementing an Angular/java webpage to work with different forms for the users.
right now if the users want to edit the pdf, the only way is to download the PDF and go to the downloads folder and open it in Adobe acrobat. Which is not an optimal solution.
Is there any way I can create a button in HTML/Angular webpage that can automate this process to open the PDF in Adobe acrobat? instead of downloading and going to download folder and open it from there?
I tried to use ngx-extended-pdf-viewer to edit the pdf in the browser. But the user needs to highlight, stamp, and email features that are in Acrobat. Does anyone have a solution for this?
thanks
You can display the pdf file in new tab by the line:
window.open(fileUrl, '_blank');
The fileUrl is a variable that contains the file path. You can fetch it after the download is complete.

Upload image automatically to instagram with Selenium in java

I am using Selenium and I need to upload an image to instagram. But at the time the windows file selector opens I could not get it to search for the image and upload it automatically
Up to this point my application opens well, when it goes to the point of selecting the file it does not do it automatically
I tried using the following codes without success
driver.findElement(By.className(name)).send_keys('C:\\path-to-file\\file.jpg')
But it gives me back the value of the second photo, that is, it generates a file selector from the main folder and not the one that I pass through as a parameter
I am using the following versions:
Java: 8
Selenium: 3.14
ChromeDriver: 76
Normal browsers don't allow JavaScript any access to the local disk. This is basic security. Imagine what would happen if you visit some site and it reads your local password file or any other important data without asking you.
If you want to upload files, take some standalone application or write a small utility that will do that. For instance, try instapy, you can find it pypi.org or on github. It is a matter of taste, the other can prefer other tools. Just try several tools and see which fits your need better.
The window opened for file explorer is not part of the browser and therefore it can not be interacted with via selenium. The solution to this is a software called AutoIt. Use the following link for a guide on how to use AutoIt for file uploads : Link

Upload file from desktop to Java applet application

How I can upload a file from desktop to Java applet application?
Create upload button.
Browse thought the desktop and choose the file.
Then create a link that enables the user to click on and open the chosen file.
use swing for example, just a button
use JFileChooser
It is not clear: do you want a link where ? (if it is on the web, you have to transmit it, or it can be on the applet: why not a button ?), and does it be called another time ?
General question: what is the purpose of this file ?

Open an exe window

I want to customize the browser by adding a new button in the main menu the requirement is when i click on the button it should open an exe its working good by opening it in a new window i want the window to be displayed in the browser itself. eg. in mozilla firefox i give a button to open openoffice.exe. Its opening as a new window and i am able to close the browser by keeping the exe file opened. I want to open the exe file of open office in the browser so that when i click the link in the window it opens the new open office writer in the browser itself. Any idea how can i implement that
An exe file (Executable) file is an independent file. It will always run in its own window no matter from where it is called. If you want to open a document in your browser window, simple link the file created in that exe file. For example if you want to show a MS-Word document in the web browser, then instead of providing the link to MS-Word, provide a link to the Word documument (.doc or docx). Remember this behaviour requires that the linked files must have a registered application installed on the computer.

Categories