Interaction with a dialog box
-
Hi I'm trying to write automation to a test a web site with C#. I'm using selenium web driver but it cannot interact with native windows. so i'm using winAPI to control a dialog window. I am trying to automaticly upload a file by interacting with the Dialog window. I have managed to get a handle on the window using the following code:
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
public const int WM_SETTEXT = 0x000C;
private void ChooseFile()
{
// retrieve the handler of the window
int iHandle = FindWindow("#32770", "File Upload");if (iHandle > 0) { //Choose File - using a string with the file path //Press OK } }
What I need to do next is choose the file to upload and then press OK to approve. Help will be much appreciated :)
-
Hi I'm trying to write automation to a test a web site with C#. I'm using selenium web driver but it cannot interact with native windows. so i'm using winAPI to control a dialog window. I am trying to automaticly upload a file by interacting with the Dialog window. I have managed to get a handle on the window using the following code:
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
public const int WM_SETTEXT = 0x000C;
private void ChooseFile()
{
// retrieve the handler of the window
int iHandle = FindWindow("#32770", "File Upload");if (iHandle > 0) { //Choose File - using a string with the file path //Press OK } }
What I need to do next is choose the file to upload and then press OK to approve. Help will be much appreciated :)
It seems like a little wrong thread, but with C++ I'd like this:
// After obtaining the dialog window handle, get the filename edit-window handle:
HANDLE hEdit=FindWindowEx(iHandle,NULL,"EDIT",NULL);// There should be only one edit window
// Update edit control:
SetWindowText(hEdit,"full filename you need");
// Simulate OK:
SendMessage(iHandle,WM_COMMAND,MAKEWPARAM(IDOK,0),(LPARAM)0);Or
// Update edit control:
SetDlgItemText(iHandle,[Edit control ID],"full filename you need");
// Simulate OK:
SendMessage(iHandle,WM_COMMAND,MAKEWPARAM(IDOK,0),(LPARAM)0);Obtain [Edit control ID] with Spy++, it must be a constant.
-
It seems like a little wrong thread, but with C++ I'd like this:
// After obtaining the dialog window handle, get the filename edit-window handle:
HANDLE hEdit=FindWindowEx(iHandle,NULL,"EDIT",NULL);// There should be only one edit window
// Update edit control:
SetWindowText(hEdit,"full filename you need");
// Simulate OK:
SendMessage(iHandle,WM_COMMAND,MAKEWPARAM(IDOK,0),(LPARAM)0);Or
// Update edit control:
SetDlgItemText(iHandle,[Edit control ID],"full filename you need");
// Simulate OK:
SendMessage(iHandle,WM_COMMAND,MAKEWPARAM(IDOK,0),(LPARAM)0);Obtain [Edit control ID] with Spy++, it must be a constant.