Monday, January 20, 2025

How one can add a picture selenium webdriver with javascript?


If you end up working in a testing firm on the automation half then add file situation is the commonest drawback. There are 03 methods to automate the identical.

  1. Utilizing selenium
  2. Utilizing AutoIT
  3. Utilizing Robotic class

Utilizing Selenium: We are able to merely add it utilizing selenium if the HTML accommodates attribute enter[@type=”file”]. if this factor shouldn’t be current within the HTML a part of the applying then it will not be attainable utilizing selenium then we have to look into one other different. Whether it is current then we will use under syntax for a similar.

WebElement upload_file = driver.findElement(By.xpath("//enter[@id='file_upload']"));
upload_file.sendKeys("C:/Customers/abc/Desktop/add.jpg");

Utilizing AutoIT:
Open the AutoIT editor.
We have to write a easy code in AutoIT editor, required for file add operation (the title of the file to be uploaded, can be talked about within the code).
Now shut the editor and proper click on on it, you will note compile script possibility.
Select compile script (x64) possibility for 64 bit machine and go along with compile script (x86) for a 32-bit machine.
As quickly because the above step is accomplished, a .exe file is created and this file can be talked about in our selenium eclipse code.
After compilation‘fileupload.exe’ file will get created.
Now we will make use of this file within the Selenium net driver script.

WebElement browser = d.findElement(By.xpath("//enter[@id='pimCsvImport_csvFile']"));   //Browse button
browser.click on();                                
Runtime.getRuntime().exec("C:CustomersChaitDesktopautoitfileupload.exe");
  Thread.sleep(3000);
 
WebElement add = d.findElement(By.id("btnSave"));     //Uploadbutton
add.click on();     
System.out.println("File Uploaded Efficiently");   // Affirmation message

When this system executes this line, it goes by way of the fileupload.exe file the place the AutoIT code is executed as proven under:
ControlFocus(“File Add”,””,”Edit1″)
ControlSetText(“File Add”,””,”Edit1″,”C:UsersChaitDesktopautoitdata_file.csv”)
ControlClick(“File Add”,””,”Button1″)

Robotic Class
Its already coated above utilizing the identical we will add.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

PHP Code Snippets Powered By : XYZScripts.com