Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I'm trying to write automation that will test a web-page with C#.
I'm using selenium web driver but it cannot interact with native windows.
The code need to automatically upload a file by interacting with a Dialog window,
so I'm trying to use C# code to control a 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 to choose the file to upload and then press OK to approve.

Help will be much appreciated!
Posted
Updated 14-Jan-13 5:26am
v2
Comments
RobScripta 14-Jan-13 12:25pm    
Could you add to your question it's about web forms. I thought I could answer your question because in Winforms I know how to do it!
ShaiBen 16-Jan-13 4:22am    
Hi,
It's a native windows dialog (which was opened by Firefox), so I don't think it's a web form.

1 solution

Hi,

Try this WatiN[^]
 
Share this answer
 
Comments
Suvabrata Roy 14-Jan-13 23:28pm    
Why this answer is down voted. WatiN is able to Handel dialog box.

http://stackoverflow.com/questions/2093290/uploading-file-in-watin
ShaiBen 16-Jan-13 4:29am    
I'm looking for a solution that does not involve more 3rd party apps, since I have already implemented all my testing framework with selenium.
but I was not the one downvoted your answer.
Suvabrata Roy 16-Jan-13 4:39am    
OkDialog Popup : Link

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900