Choose File to Upload Window Java Seleniu
In this tutorial, nosotros will larn How to use AutoIt in Selenium and How to upload files using AutoIt.
What is AutoIt?
AutoIt is an open up source tool that is employ for perform windows based performance like handle window alert. Also we can use in combination of mouse-move, keystrokes operations. Nosotros are well known that selenium web driver merely work on web based related application. So when we face window alert then we take to use this tool. It is too using in to uploading the files which we are going to discuss.
Stride by Step How to apply AutoIt in Selenium:
- Download and Install AutoIt.
- Open AutoIt identifier and find attribute of the elements like title, grade and instance.
- Open AutoIt editor and write some code to perform select file, mouse click operation.
- At the end write code in selenium script.
- Download and Install AutoIt –
For download AutoIt, use this link- Download AutoIt
By clicking on Download AutoIt, It will be downloaded so clicking on "autoit-v3-setup.exe" setup, information technology volition exist installed. Now become to installed folder (In Plan files) we can see SciTE.exe file. By clicking on this we can encounter AutoIt editor and nosotros can see Au3Info.exe, that is AutoIt Identifier to finding the attribute of the elements.
- Open up AutoIt identifier and find aspect of the elements like championship, class and instance:If I want to upload a file and then first I clicked on "Upload File" push button then a window popup volition be opened to select file from your computer. Here nosotros will use AutoIt identifier to find window popup element attributes.
Past using finder tool (Click on Finder tool with property left mouse button and drag information technology on file proper name edit box ) find the attributes(Title, Form, Instance) of File name edit box. See in below image we have found these attributes are:
Title —> Open up
Form –> Edit
Example –> 1
Aforementioned like we volition drag finder tool on "Open" push button in window popup and find attributes of this button:
Title –> Open
Course –> Push button
Case –> 1
- Now, Open AutoIt editor and write some lawmaking to perform select file, mouse click performance.a) Click on SciTE folder to open autoit editor.
b) Click on SciTE file. Now Editor volition exist open.
In this we will write 3 lines code. In this we volition use "ControlFocus", "ControlSetText" and "ControlClick" methods.
ControlFocus("title","text","ControlID");
ControlSetText("title","text","ControlID","File Path which we desire to upload");
ControlClick("title","text","ControlID");
a) Write code for "File name" text box.
– Offset attribute is 'title' which is 'Open'.
– Second attribute is 'text' which is not required.
– Third attribute is 'ControlID' which is Edit1 (combination of Course and Instance);
b) Write code for select file which nosotros want to upload using ControlSetText method
– First aspect is 'title' which is 'Open'.
– Second attribute is 'text' which is not required.
– Third attribute is 'ControlID' which is Edit1.
– 4th is path of file which we want to upload.
c) Write code for click Open button.
– Beginning attribute is 'title' which is 'Open'.
– Second aspect is 'text' which is not required.
– Third attribute is 'ControlID' which is Button1. (Here controlid is Button1)
Now save this editor file with .au3 extension.
Afterward salvage this file, Compile it by right click on it. (Compile script on the basis of your OS bit. ). After compilation a .exe file volition be generated.
Now open the eclipse and write the code for upload file.
1. Write the code for click on "upload file" button.
driver.findElement(Past.xpath("locator of upload file button")).click();
2. Write code for run the .exe file which nosotros have created above.
Runtime.getRunTime.exec("C:\\Users\\Aj\\New binder\\FileUpload.exe");
How To Upload File in Selenium WebDriver without using AutoIT:
There are two other methods to upload the file without using Selenium.
- Using sendkeys
- Using Robot class
#Using sendKeys method: This is basic mode to upload the file in selenium.
Syntax:
WebElement uploadfile = driver.findElement(By.xpath("//input[@id='file']"));
uploadfile.sendKeys("C:/Users/Ajeet/Desktop/upload.png");
#Using Robot Form: Nosotros can perform the various activities using Robot course such as mouse functions, keywords functions and many more than.
Read below link to upload files using Robot Class.
Upload files using Robot Class
How To Handle Window Authentication Popup using AutoIt:
Sometimes when we navigate any website which contains window authentication popup which ask for Username and Password so while running selenium script we cannot navigate to parent window.
Now nosotros will discuss How to handle window authenticate popup. There are two means to handle it.
1.We tin provide credentials in URL itself. We will add username and password in URL then while running script it will bypass the same.
Example:
http://ajeetmaurya:[e-mail protected]
ii. In this approach we will use AutoIt which we accept already discussed. Delight read above department for AutoIt.
Summary:
In this postal service, we have covered ' How To Upload Files Using AutoIt'.
We have likewise covered – How to handle window authentication popup using AutoIt, How to upload file in Selenium WebDriver without using AutoIT.
I am sure this content added some boosted value in your skills and besides helpful to preparation of your interviews.
Terminal word, Bookmark this postal service " How To Upload Files Using AutoIt " for future reference.
If you accept other questions or feedback, the comment department is yours. Don't forget to leave a annotate beneath!
Source: https://automationtestings.com/how-upload-files-using-autoit-selenium/
0 Response to "Choose File to Upload Window Java Seleniu"
Post a Comment