1

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

Refer the attached screenshot

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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 :)

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.