Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows API
  4. Interaction with a dialog box

Interaction with a dialog box

Scheduled Pinned Locked Moved Windows API
csharpc++testingtoolshelp
3 Posts 3 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    ShaiBen
    wrote on last edited by
    #1

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

    A 1 Reply Last reply
    0
    • S ShaiBen

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

      A Offline
      A Offline
      anton_V1
      wrote on last edited by
      #2

      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.

      L 1 Reply Last reply
      0
      • A anton_V1

        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.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Assuming that it is your dialog in case 2 then you should already know the dialog item id. Perhaps you could give some more detail on exactly what it is you are trying to do.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups