WebBrowser Auto-Populate Open File dialog box

Source: Internet
Author: User

WebBrowser AutoFill Open File dialog box

June 24, 2013 ⁄ code ⁄ a total of 1456 characters ⁄ font size small big ⁄ no comments ⁄ read 882 views

When using WebBrowser to write automatic form filling software, I do not know if you have encountered the state to fill in the document selection form. In this case, it is not possible to directly assign the team HTML elements, you must simulate the method of manual selection (whether there are other solutions, not known), let us consider my solution, as follows:

1, first talk about the normal form of the filling method, in the Delphi+webbrowser environment, can use the following code:

1

WebBrowser.OleObject.document.all.item (' XXX ', 0). Value: =xxx;

2, for the file selection form, we can first simulate the click, open the File selection dialog box:

1

WebBrowser.OleObject.document.all.item (' click ', 0). value;

3, then we take the enumeration subform method, find the file input location, and the "OK" button to simulate the selection of files:

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

//...

function Enumproc (hwnd:thandle; Lb:longint): Boolean; stdcall;

//...

function Enumproc (hwnd:thandle; Lb:longint): Boolean; stdcall;

var cname:array[0..255] of Char;

path:string;

I:integer;

Begin

GetClassName (Hwnd, CName, 255);

If CName = ' Edit ' Then

Begin

Path: = Extractfilepath (application.exename) + ' retrieval \ ' + NameStr + '. bmp ';

For I: = 1 to Length (path) does

Begin

PostMessage (Hwnd, WM_CHAR, WPAram (Path[i]), 1);

End

The number of times to simulate the selection of files is to fill the location of the file in the selection box.

End

if (Tname = ' open (&o) ') or (tname = ' OK ') then

Begin

PostMessage (Hwnd, wm_lbuttondown, 0, 0);

PostMessage (Hwnd, wm_lbuttonup, 0, 0);

Click here to simulate

End

Result: = True;

End

//...

Procedure Findwin ();//Call

var Hwnd:thandle;

Begin

HWND: = FindWindow (nil, Title);

Title Select Window Caption for file

If Hwnd <> 0 Then

Begin

Enumchildwindows (Hwnd, @EnumProc, LP);

End

End

3. Matters needing attention:

Upload File Form dialog box

A, select the File dialog window title, under different IE kernel is not the same, I tested on Win7 and XP is the "Select File", "Choose to load the file."
b, in the simulation when filling in, you need to note that when prompted to open the file, the code run is paused, that is, you have to open the simulation in the thread.

C, in the name of the input, do not use the SetWindowText function, this function can not be implemented, can only be sent WM_CHAR message, the way to simulate character input.
4, finally warned everyone, if there is no special encryption algorithm, or other restrictions, try to directly use the HTTP protocol to submit the form, or some things too cumbersome.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.