Selenium itself cannot handle windows controls, and requires the help of AutoIt
AUTOIT3 syntax is simple, such as the Windows dialog box that handles uploading files
Controlfocus ("Please select Upload file", "", "Edit1")
Controlsettext ("Please select Upload file", "" "," Edit1 "," D:\upload.txt ")
Sleep (2000)
Controlclick ("Please select Upload file", "", "Button1");
These methods are basically similar in syntax:
First parameter: Title/hwnd/class
Controlclick ($hWnd, "", "Edit1")
Controlclick ("title", "", "Edit1")
Controlclick ("[CLASS: #32770]", "", "Edit1")
Controlid:id text,class,classnn,name,instance
such as: button1; [Id:1003];1003 (ID), "[Classnn:edit1]", "Save (&s)", [Class:button;instance:1], "[Name:textboxfolder]",
For example: The above statement can also be written like this
Controlfocus ("[CLASS: #32770]", "", "Edit1")
$hwnd =winwait ("[CLASS: #32770]", "", 5)
Controlsettext ($hwnd, "", "Edit1", $filename)
Sleep (2000)
Controlclick ("[CLASS: #32770]", "", "Save (&s)")
If you need to pass parameters, you need to encapsulate the function, the AutoIt parameter form is: $CmdLine [0] is the number of arguments, $CmdLine [1] represents the first parameter, and so on, such as multiple parameters, called, when the middle with a space split, such as Upload.exe param1 Param2
SaveAs ($CmdLine [1])
Func SaveAs ($filename)
Winactve ("[CLASS: #32770]")
Controlfocus ("Please select Upload file", "", "Edit1")
Controlsettext ("Please select Upload file", "", "Edit1", $filename)
Sleep (2000)
Controlclick ("Please select Upload file", "", "Button1");
Endfunc
Converted to an EXE file, you can directly invoke the
Java calls:
public static void SaveFile (String filepath) {
String command = "E:\\upload.exe" + "" +filepath;
try {
Runtime.getruntime (). exec (command);
} catch (IOException e) {
E.printstacktrace ();
}
}
Of course QTP can also be called:
CreateObject ("Wscript.Shell"). Run "D:\upload.exe"
Selenium using AUTOIT3 to process Windows controls