0

I have selenium script that is going through website to get a quote then gets to file upload, click on element and file upload window opens. My AutoIt script is below and it works when I execute it manually.

WinWait("[CLASS:#32770]","",10)
ControlFocus("File Upload", "", 1148)
Sleep(2000)
ControlSetText("File Upload", "", 1148, "C:\Users\kmaklakova\IdeaProjects\WizardLabelsRegression\vector.jpg") 
Sleep(2000)
ControlClick("File Upload", "", 1)

When i try to run it during Java runtime it exits with ecit code 1

    uploadArea1.click();

    Process p = Runtime.getRuntime().exec("C:\\AutoIt3\\new.exe");
    p.waitFor();
    if (p.exitValue()==1) {
        System.out.println("YAY!");
    }
    else {
        System.out.println("boo");
    }
    label1Name.setValue("test");

Does anyone know what is the reason?

2 Answers 2

1

Have you tried to use the following portion to execute your autoIT instead of using Process "Runtime.getRuntime().exec("C:\AutoIt3\new.exe"); and use some wait in order to have the file uploaded.

Please note that I'm talking about running the "CMD" command only, not about the implementation of your upload file script.

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

4 Comments

Yes, I did both things and it's the same thing.
try the following, replace the "\\" with this / and can you confirm that you have used Thread.sleep().
So I changed it \\ to / and added Thread.sleep(5000); uploadArea1.click(); Thread.sleep(5000); Runtime.getRuntime().exec("C:/AutoIt3/new.exe"); and still the same
The last hope is to use the sleep between the uploadArea1.click() and the execution of upload script, because if the computer has average performance it needs time for the pop up of the file uploader to be displayed during the time your .exe script will be started and failed because it couldn't find the upload file window. Please check and let me know if it work.
0

You have to put some sleep after the element click. Here is the modified code :

uploadArea1.click();
Thread.sleep(5000);
Process p = Runtime.getRuntime().exec("C:\\AutoIt3\\new.exe");
p.waitFor();
if (p.exitValue()==1) {
    System.out.println("YAY!");
}
else {
    System.out.println("boo");
}
label1Name.setValue("test");

run this code and it works like charm.

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.