automate image upload from windows explore with selenium and AutoIT - selenium

I have to automate a scenario like a upload an image from windows explorer to TinyMCE component using Selenium. Since Selenium does not support OS control, I used AutoIt to upload the image.
AutiIt sets the image path to "File name" and seems like it clicks on 'Open' button as well. But the image is not loading to my "source" field.
Here is my Selenium command:
Runtime.getRuntime().exec("C:/XXXXX/src/test/resources/uploadImage.exe");
// Path of the AutoIT script file
AutoIT script:
WinActivate("Open")
Send("C:\LCNGProjects\Screenshots\Images\GifImage1.gif")
Sleep(5000)
Send("{ENTER}")
Refer the attached screenshot

Not sure if I have got the questions correct, Did you compile the script.
Can you please go through link below for script compilation and step by step info how to upload a file.
https://www.guru99.com/use-autoit-selenium.html

You do not need to use AutoIt. Auto will make your script dependable on windows machine only.
Instead of it find element using locator(i.e. xpath) of upload button which is having tag as type="file". Now pass this simple sendKeys with absolute path of your image in your machine like below:-
button2.sendKeys("C:\\UsersDesktop\\logo\\Summit-Logo-900px.png");
Or use
System.getProperty("user.dir"));
Append the path of file exluding your project path and filename inside your project
Example :-
button.sendKeys(System.getProperty("user.dir")+"\\logo\\Summit-Logo-900px.png");
below link contains more option to upload file like below :-
Using SendKeys command.
Using AutoIt scripting.
Using Jacob com interface.
http://www.techbeamers.com/handle-file-upload-selenium-webdriver/#h3
Hope it will help you :)

I'm not going to add full source code here. You can call the AutoIT script using this command inside your test case.
// Call to AutoIT script to upload the image
Runtime.getRuntime().exec("C:\\xxxxx\\src\\test\\resources\\uploadImage.exe");
AutoIT Scrip
ControlFocus("Open","","Edit1")
ControlSetText("Open","","Edit1","C:\xxxx\Images\jpgImage")
ControlClick("Open","","Button1")
For more information refer the following link
https://www.guru99.com/use-autoit-selenium.html

Related

how to upload file in headless mode without button tag

Is there any way to upload a file using rebot framework without tag and with the headless mode activated. I tried to use AutoIt and sikuliLibrary but they are not working .
best Regards
If you have an input element, you can use Choose File keyword :
Choose File id=input_id C://document/file.txt
Check the documentation : https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Choose%20File
You can upload the file with Selenium by sending the file you want to upload to a special file.
This will work regardless to the headless or regular Selenium mode.
With Python language syntax it will be:
driver.find_element_by_xpath("//input[#type='file']").send_keys("the_full_path_to_your_file")
With other languages it will be similar, just with some syntax changes.

how to handle file upload case in ubuntu machine using selenium with java

driver.findElement(By.xpath("//div[#class='invoiceUploadButton mat-elevation-z1 fileBrowseContainer']")).click();
with this i am able to click on choose file button to upload file.But after it i have a window pop-up to upload respective file. How to upload my file here? It works only in windows machine.
HTML Dom reference
<div class="invoiceUploadButton mat-elevation-z1 fileBrowseContainer">
<span>Choose File</span>
</div>
Try using the sendKeys method to provide the file path and then hit the Upload or Ok button.
addFile.sendKeys("D:\Big Data on AWS\Images\caps.jpeg");
driver.findElement(//Upload button).click();

How to automate upload file with double click without using send keys in selenium java?

Trying to automate using the below code but not working
Actions actions = new Actions(driver);
fileupoladbtn.sendKeys(System.getProperty("user.dir") +"/Images/zoom_out.jpg");
actions.dragAndDrop(fileupoladbtn, fileupoladbtn1);
what I could understand from your short described question , you need to interact with windows file upload which is not handled by selenium , you need to use auto it scrip and call that in your selenium script.you can download Auto it and SCiTE which is the editor.
below is the autoit file upload script -
Sleep(1000)
ControlFocus("Open","","Edit1")
Sleep(2000)
Send("{Enter}")
Sleep(1000)
Send("{Backspace}")
Sleep(1000)
Send($CmdLine[1])
Send("{Enter}")
Sleep(2)
ControlClick("Open","","Button1")
It will be saved when you go to tools and compile it in autoit editor, note the name from here.
once action to popup file upload is done, and Window handler to file upload is visible call above script.
for Java
Runtime.getRuntime().exec("E:\\AutoIT\\FileUpload.exe");
for Python
subprocess.Popen('C:\\Handle\\FileUpload.exe '+File_path, shell=True)
More Details
https://www.autoitscript.com/site/autoit/downloads/
https://www.guru99.com/use-autoit-selenium.html

Handle Windows Open File dialog in Selenium

How can handle Window Open File dialog (set file path and import) using javascript (or some other way) in Selenium ?
If you are trying to upload a file, and the page in question uses the standard upload mechanisms provided by HTML, you can do this directly with Selenium itself. The standard HTML mechanism is with an <input type=‘file’> element. Once you’ve found that file upload element on the page, you can use element.sendKeys(“full/path/and/file/name/here”);. This is documented in Step 10 of the algorithm for the Element Send Keys command of the W3C WebDriver Specification, and is used in several file upload tests in the Selenium project’s test code (example).
//set file path
driver.findelelment(By.Xpath("//input[contains(#type,'file')]")).SendKeys(UploadFilePath);

How to upload a file using Selenium IDE V2.9.0

I have a scenario where in i need to upload a file using Selenium IDE version 2.9.0.
I tried using "Type" command with id of that element and path of that file as argument. But its not working.
Is there any other way to upload a file using IDE?
If there is no other way to upload using IDE, then what might be the issue? Please suggest
Try this:
getDriver().findElement(YourUploadButton).sendkeys(uploadFilepath);