Loading ...
Sorry, an error occurred while loading the content.

Auto form fill

Expand Messages
  • Robert Baker <zxytek@yahoo.com>
    I am able to navigate to and fill Web form pages at will, EXCEPT if the field is a type= file . I am unable to force anything into the value [i.e.
    Message 1 of 13 , Jan 24, 2003
    • 0 Attachment
      I am able to navigate to and "fill" Web form pages at will,
      EXCEPT if the <input> field is a type="file". I am unable to force
      anything into the "value" [i.e. FormItem.Item(j).value:= 'whatever']
      from my Delph code. Is there a "trick" to the type="file" input's
      or have I missed something here?

      TYIA,

      Robert Baker

      FROM THE HTML:

      WORKS: <input name="user_id" type=text size=20 maxlength=64 value="">

      DOESN'T WORK: <input type="file" size="30" name="myfieldname"
      value="" title="Select File">

      DELPHI CODE:
      var
      i,j:Integer;
      FormItem:Variant;
      begin
      for i:=0 to WebBrowser1.OleObject.Document.forms.Length -1 do
      begin
      FormItem := WebBrowser1.OleObject.Document.forms.Item(i);
      For j:= 0 to FormItem.Length-1 do
      begin
      try
      if FormItem.Item(j).name = 'myfieldname' then
      FormItem.Item(j).value:= 'myfieldvalue';
      except
      exit;
      end;
      end;
      end;
    • geppakazol <geppakazol@yahoo.com>
      Without having the time, for the moment, to try any of these, I would suggest the following two approaches: 1: ...window.clipboarData.clearData;
      Message 2 of 13 , Jan 25, 2003
      • 0 Attachment
        Without having the time, for the moment, to try any of these, I
        would suggest the following two approaches:

        1: ...window.clipboarData.clearData;
        ...window.clipboarDdata.setData('Text','your desired file');
        ...<input>.Focus;
        ...<input>.Select;
        ...document.execCommand('Paste')
        ...<form>.Submit;


        2: ...s:string;
        s:=...document.Body.innerHTML;
        - parse s for your input and change it's value
        ...document.Write('');document.Close;
        ...document.Write(s);document.Close;
        ...<form>.Submit

        I hope it helps, even though what I wrote in not JavaScript,
        JScript nor Delphi code.



        --- In delphi-webbrowser@yahoogroups.com, "Robert Baker
        <zxytek@y...>" <zxytek@y...> wrote:
        > I am able to navigate to and "fill" Web form pages at will,
        > EXCEPT if the <input> field is a type="file". I am unable to force
        > anything into the "value" [i.e. FormItem.Item
        (j).value:= 'whatever']
        > from my Delph code. Is there a "trick" to the type="file" input's
        > or have I missed something here?
        >
        > TYIA,
        >
        > Robert Baker
        >
        > FROM THE HTML:
        >
        > WORKS: <input name="user_id" type=text size=20 maxlength=64
        value="">
        >
        > DOESN'T WORK: <input type="file" size="30" name="myfieldname"
        > value="" title="Select File">
        >
        > DELPHI CODE:
        > var
        > i,j:Integer;
        > FormItem:Variant;
        > begin
        > for i:=0 to WebBrowser1.OleObject.Document.forms.Length -1 do
        > begin
        > FormItem := WebBrowser1.OleObject.Document.forms.Item(i);
        > For j:= 0 to FormItem.Length-1 do
        > begin
        > try
        > if FormItem.Item(j).name = 'myfieldname' then
        > FormItem.Item(j).value:= 'myfieldvalue';
        > except
        > exit;
        > end;
        > end;
        > end;
      • Robert Baker <rbaker@vlp-xp.com>
        I finally found out that the is a read-only control so I used the code below [its tested] to resolve the problem. Thought I would share it
        Message 3 of 13 , Jan 25, 2003
        • 0 Attachment
          I finally found out that the <input type-file> is a "read-only"
          control so I used the code below [its tested] to resolve the
          problem. Thought I would share it with anybody else that needs an
          immediate solution. Thanks you for your suggestions, your solutions
          look like they may be a little cleaner than mine; I will try them to
          learn and better understand how to control the browser from Delphi.
          I now have another issue with confirmation popups that I will post
          in a new thread.

          for I:=0 to WebBrowser1.OleObject.Document.forms.Length -1 do
          begin
          FormItem := WebBrowser1.OleObject.Document.forms.Item(I);
          For j:= 0 to FormItem.Length-1 do
          begin
          try
          if (FormItem.Item(j).Name = 'myfileinput')
          and (uppercase(FormItem.Item(j).type) = 'FILE')
          then begin
          FormItem.Item(j).focus;
          Sendkeys(Edit4.Text);
          end;
          except
          exit;
          end;
          end;
          end;

          Thanks again,
          Robert Baker
        • dalewolver <dwolver@telusplanet.net>
          This is great. I tried figuring out how to fill in those readonly fields for File Input and everywhere you look indicates it could not be done. Whoever came up
          Message 4 of 13 , Jan 27, 2003
          • 0 Attachment
            This is great. I tried figuring out how to fill in those readonly
            fields for File Input and everywhere you look indicates it could not
            be done.
            Whoever came up with this solution, thanks a bunch!!

            --- In delphi-webbrowser@yahoogroups.com, "Robert Baker
            <rbaker@v...>" <rbaker@v...> wrote:
            > I finally found out that the <input type-file> is a "read-only"
            > control so I used the code below [its tested] to resolve the
            > problem. Thought I would share it with anybody else that needs an
            > immediate solution. Thanks you for your suggestions, your solutions
            > look like they may be a little cleaner than mine; I will try them
            to
            > learn and better understand how to control the browser from
            Delphi.
            > I now have another issue with confirmation popups that I will post
            > in a new thread.
            >
            > for I:=0 to WebBrowser1.OleObject.Document.forms.Length -1 do
            > begin
            > FormItem := WebBrowser1.OleObject.Document.forms.Item(I);
            > For j:= 0 to FormItem.Length-1 do
            > begin
            > try
            > if (FormItem.Item(j).Name = 'myfileinput')
            > and (uppercase(FormItem.Item(j).type) = 'FILE')
            > then begin
            > FormItem.Item(j).focus;
            > Sendkeys(Edit4.Text);
            > end;
            > except
            > exit;
            > end;
            > end;
            > end;
            >
            > Thanks again,
            > Robert Baker
          • Carrz KISS @ Carrz-Fox-Fire Promotions
            Hello What exactly do you mean by: Read Only -- Fields??? Could you please send me a link to a page that is Read Only As I have
            Message 5 of 13 , Jan 27, 2003
            • 0 Attachment
              Hello <dwolver@...>

              What exactly do you mean by: Read Only -- Fields???
              Could you please send me a link to a page that is "Read Only"
              As I have been having some problems inputting data into some fields on eBay.
              I can do all of them, except the "Bid Login page" (The page that it takes
              you to, to login after you have entered your Bid amount)

              Thanks for the information
              Wayne


              > This is great. I tried figuring out how to fill in those readonly
              > fields for File Input and everywhere you look indicates it could not
              > be done.
              > Whoever came up with this solution, thanks a bunch!!
              >

              > >
              > > for I:=0 to WebBrowser1.OleObject.Document.forms.Length -1 do
              > > begin
              > > FormItem := WebBrowser1.OleObject.Document.forms.Item(I);
              > > For j:= 0 to FormItem.Length-1 do
              > > begin
              > > try
              > > if (FormItem.Item(j).Name = 'myfileinput')
              > > and (uppercase(FormItem.Item(j).type) = 'FILE')
              > > then begin
              > > FormItem.Item(j).focus;
              > > Sendkeys(Edit4.Text);
              > > end;
              > > except
              > > exit;
              > > end;
              > > end;
              > > end;
              > >
              > > Thanks again,
              > > Robert Baker
            • Carrz KISS @ Carrz-Fox-Fire Promotions
              ... USING DELPHI 6.02 in the code above. The [ Sendkeys(Edit4.Text); ] I am getting a compiling error, Is this a component??? As I have found a Sendkeys
              Message 6 of 13 , Jan 29, 2003
              • 0 Attachment
                > > for I:=0 to WebBrowser1.OleObject.Document.forms.Length -1 do
                > > begin
                > > FormItem := WebBrowser1.OleObject.Document.forms.Item(I);
                > > For j:= 0 to FormItem.Length-1 do
                > > begin
                > > try
                > > if (FormItem.Item(j).Name = 'myfileinput')
                > > and (uppercase(FormItem.Item(j).type) = 'FILE')
                > > then begin
                > > FormItem.Item(j).focus;
                > > Sendkeys(Edit4.Text);
                > > end;
                > > except
                > > exit;
                > > end;
                > > end;
                > > end;
                > >

                USING DELPHI 6.02


                in the code above. The [ Sendkeys(Edit4.Text); ]
                I am getting a compiling error, Is this a component??? As I have found a
                "Sendkeys" Component For Delphi 2-5
                But not for Delphi 6??

                Could someone please let me know about this, As I think that this little
                code sniplet is exactly what I need.

                Thank you
                Wayne
              • dwolver
                There is a sndkey32.pas file in the Delphi5 cd in one of the extra folders. I have attached it to this reply, hopefully it shows up. dale ... From: Carrz KISS
                Message 7 of 13 , Jan 29, 2003
                • 0 Attachment
                  There is a sndkey32.pas file in the Delphi5 cd in one of the extra folders.
                  I have attached it to this reply, hopefully it shows up.
                  dale



                  ----- Original Message -----
                  From: "Carrz KISS @ Carrz-Fox-Fire Promotions"
                  <carrzkiss@...>
                  To: <delphi-webbrowser@yahoogroups.com>
                  Sent: Wednesday, January 29, 2003 7:55 AM
                  Subject: Re: [delphi-webbrowser] Re: Auto form fill



                  [Non-text portions of this message have been removed]
                • dwolver
                  Well I guess attachments dont show up. so... (* SendKeys routine for 32-bit Delphi. Written by Ken Henderson Copyright (c) 1995 Ken Henderson
                  Message 8 of 13 , Jan 29, 2003
                  • 0 Attachment
                    Well I guess attachments dont show up.
                    so...

                    (*
                    SendKeys routine for 32-bit Delphi.

                    Written by Ken Henderson

                    Copyright (c) 1995 Ken Henderson email:khen@...

                    This unit includes two routines that simulate popular Visual Basic
                    routines: Sendkeys and AppActivate. SendKeys takes a PChar
                    as its first parameter and a boolean as its second, like so:

                    SendKeys('KeyString', Wait);

                    where KeyString is a string of key names and modifiers that you want
                    to send to the current input focus and Wait is a boolean variable or value
                    that indicates whether SendKeys should wait for each key message to be
                    processed before proceeding. See the table below for more information.

                    AppActivate also takes a PChar as its only parameter, like so:

                    AppActivate('WindowName');

                    where WindowName is the name of the window that you want to make the
                    current input focus.

                    SendKeys supports the Visual Basic SendKeys syntax, as documented below.

                    Supported modifiers:

                    + = Shift
                    ^ = Control
                    % = Alt

                    Surround sequences of characters or key names with parentheses in order to
                    modify them as a group. For example, '+abc' shifts only 'a', while '+(abc)'
                    shifts
                    all three characters.

                    Supported special characters

                    ~ = Enter
                    ( = Begin modifier group (see above)
                    ) = End modifier group (see above)
                    { = Begin key name text (see below)
                    } = End key name text (see below)

                    Supported characters:

                    Any character that can be typed is supported. Surround the modifier keys
                    listed above with braces in order to send as normal text.

                    Supported key names (surround these with braces):

                    BKSP, BS, BACKSPACE
                    BREAK
                    CAPSLOCK
                    CLEAR
                    DEL
                    DELETE
                    DOWN
                    END
                    ENTER
                    ESC
                    ESCAPE
                    F1
                    F2
                    F3
                    F4
                    F5
                    F6
                    F7
                    F8
                    F9
                    F10
                    F11
                    F12
                    F13
                    F14
                    F15
                    F16
                    HELP
                    HOME
                    INS
                    LEFT
                    NUMLOCK
                    PGDN
                    PGUP
                    PRTSC
                    RIGHT
                    SCROLLLOCK
                    TAB
                    UP

                    Follow the keyname with a space and a number to send the specified key a
                    given number of times (e.g., {left 6}).
                    *)

                    unit sndkey32;

                    interface

                    Uses SysUtils, Windows, Messages;

                    Function SendKeys(SendKeysString : PChar; Wait : Boolean) : Boolean;
                    function AppActivate(WindowName : PChar) : boolean;

                    {Buffer for working with PChar's}

                    const
                    WorkBufLen = 40;
                    var
                    WorkBuf : array[0..WorkBufLen] of Char;

                    implementation
                    type
                    THKeys = array[0..pred(MaxLongInt)] of byte;
                    var
                    AllocationSize : integer;

                    (*
                    Converts a string of characters and key names to keyboard events and
                    passes them to Windows.

                    Example syntax:

                    SendKeys('abc123{left}{left}{left}def{end}456{left 6}ghi{end}789', True);

                    *)

                    Function SendKeys(SendKeysString : PChar; Wait : Boolean) : Boolean;
                    type
                    WBytes = array[0..pred(SizeOf(Word))] of Byte;

                    TSendKey = record
                    Name : ShortString;
                    VKey : Byte;
                    end;

                    const
                    {Array of keys that SendKeys recognizes.

                    If you add to this list, you must be sure to keep it sorted alphabetically
                    by Name because a binary search routine is used to scan it.}

                    MaxSendKeyRecs = 41;
                    SendKeyRecs : array[1..MaxSendKeyRecs] of TSendKey =
                    (
                    (Name:'BKSP'; VKey:VK_BACK),
                    (Name:'BS'; VKey:VK_BACK),
                    (Name:'BACKSPACE'; VKey:VK_BACK),
                    (Name:'BREAK'; VKey:VK_CANCEL),
                    (Name:'CAPSLOCK'; VKey:VK_CAPITAL),
                    (Name:'CLEAR'; VKey:VK_CLEAR),
                    (Name:'DEL'; VKey:VK_DELETE),
                    (Name:'DELETE'; VKey:VK_DELETE),
                    (Name:'DOWN'; VKey:VK_DOWN),
                    (Name:'END'; VKey:VK_END),
                    (Name:'ENTER'; VKey:VK_RETURN),
                    (Name:'ESC'; VKey:VK_ESCAPE),
                    (Name:'ESCAPE'; VKey:VK_ESCAPE),
                    (Name:'F1'; VKey:VK_F1),
                    (Name:'F10'; VKey:VK_F10),
                    (Name:'F11'; VKey:VK_F11),
                    (Name:'F12'; VKey:VK_F12),
                    (Name:'F13'; VKey:VK_F13),
                    (Name:'F14'; VKey:VK_F14),
                    (Name:'F15'; VKey:VK_F15),
                    (Name:'F16'; VKey:VK_F16),
                    (Name:'F2'; VKey:VK_F2),
                    (Name:'F3'; VKey:VK_F3),
                    (Name:'F4'; VKey:VK_F4),
                    (Name:'F5'; VKey:VK_F5),
                    (Name:'F6'; VKey:VK_F6),
                    (Name:'F7'; VKey:VK_F7),
                    (Name:'F8'; VKey:VK_F8),
                    (Name:'F9'; VKey:VK_F9),
                    (Name:'HELP'; VKey:VK_HELP),
                    (Name:'HOME'; VKey:VK_HOME),
                    (Name:'INS'; VKey:VK_INSERT),
                    (Name:'LEFT'; VKey:VK_LEFT),
                    (Name:'NUMLOCK'; VKey:VK_NUMLOCK),
                    (Name:'PGDN'; VKey:VK_NEXT),
                    (Name:'PGUP'; VKey:VK_PRIOR),
                    (Name:'PRTSC'; VKey:VK_PRINT),
                    (Name:'RIGHT'; VKey:VK_RIGHT),
                    (Name:'SCROLLLOCK'; VKey:VK_SCROLL),
                    (Name:'TAB'; VKey:VK_TAB),
                    (Name:'UP'; VKey:VK_UP)
                    );

                    {Extra VK constants missing from Delphi's Windows API interface}
                    VK_NULL=0;
                    VK_SemiColon=186;
                    VK_Equal=187;
                    VK_Comma=188;
                    VK_Minus=189;
                    VK_Period=190;
                    VK_Slash=191;
                    VK_BackQuote=192;
                    VK_LeftBracket=219;
                    VK_BackSlash=220;
                    VK_RightBracket=221;
                    VK_Quote=222;
                    VK_Last=VK_Quote;

                    ExtendedVKeys : set of byte =
                    [VK_Up,
                    VK_Down,
                    VK_Left,
                    VK_Right,
                    VK_Home,
                    VK_End,
                    VK_Prior, {PgUp}
                    VK_Next, {PgDn}
                    VK_Insert,
                    VK_Delete];

                    const
                    INVALIDKEY = $FFFF {Unsigned -1};
                    VKKEYSCANSHIFTON = $01;
                    VKKEYSCANCTRLON = $02;
                    VKKEYSCANALTON = $04;
                    UNITNAME = 'SendKeys';
                    var
                    UsingParens, ShiftDown, ControlDown, AltDown, FoundClose : Boolean;
                    PosSpace : Byte;
                    I, L : Integer;
                    NumTimes, MKey : Word;
                    KeyString : String[20];

                    procedure DisplayMessage(Message : PChar);
                    begin
                    MessageBox(0,Message,UNITNAME,0);
                    end;

                    function BitSet(BitTable, BitMask : Byte) : Boolean;
                    begin
                    Result:=ByteBool(BitTable and BitMask);
                    end;

                    procedure SetBit(var BitTable : Byte; BitMask : Byte);
                    begin
                    BitTable:=BitTable or Bitmask;
                    end;

                    Procedure KeyboardEvent(VKey, ScanCode : Byte; Flags : Longint);
                    var
                    KeyboardMsg : TMsg;
                    begin
                    keybd_event(VKey, ScanCode, Flags,0);
                    If (Wait) then While (PeekMessage(KeyboardMsg,0,WM_KEYFIRST, WM_KEYLAST,
                    PM_REMOVE)) do begin
                    TranslateMessage(KeyboardMsg);
                    DispatchMessage(KeyboardMsg);
                    end;
                    end;

                    Procedure SendKeyDown(VKey: Byte; NumTimes : Word; GenUpMsg : Boolean);
                    var
                    Cnt : Word;
                    ScanCode : Byte;
                    NumState : Boolean;
                    KeyBoardState : TKeyboardState;
                    begin
                    If (VKey=VK_NUMLOCK) then begin
                    NumState:=ByteBool(GetKeyState(VK_NUMLOCK) and 1);
                    GetKeyBoardState(KeyBoardState);
                    If NumState then KeyBoardState[VK_NUMLOCK]:=(KeyBoardState[VK_NUMLOCK]
                    and not 1)
                    else KeyBoardState[VK_NUMLOCK]:=(KeyBoardState[VK_NUMLOCK] or 1);
                    SetKeyBoardState(KeyBoardState);
                    exit;
                    end;

                    ScanCode:=Lo(MapVirtualKey(VKey,0));
                    For Cnt:=1 to NumTimes do
                    If (VKey in ExtendedVKeys)then begin
                    KeyboardEvent(VKey, ScanCode, KEYEVENTF_EXTENDEDKEY);
                    If (GenUpMsg) then
                    KeyboardEvent(VKey, ScanCode, KEYEVENTF_EXTENDEDKEY or
                    KEYEVENTF_KEYUP)
                    end else begin
                    KeyboardEvent(VKey, ScanCode, 0);
                    If (GenUpMsg) then KeyboardEvent(VKey, ScanCode, KEYEVENTF_KEYUP);
                    end;
                    end;

                    Procedure SendKeyUp(VKey: Byte);
                    var
                    ScanCode : Byte;
                    begin
                    ScanCode:=Lo(MapVirtualKey(VKey,0));
                    If (VKey in ExtendedVKeys)then
                    KeyboardEvent(VKey, ScanCode, KEYEVENTF_EXTENDEDKEY and KEYEVENTF_KEYUP)
                    else KeyboardEvent(VKey, ScanCode, KEYEVENTF_KEYUP);
                    end;

                    Procedure SendKey(MKey: Word; NumTimes : Word; GenDownMsg : Boolean);
                    begin
                    If (BitSet(Hi(MKey),VKKEYSCANSHIFTON)) then SendKeyDown(VK_SHIFT,1,False);
                    If (BitSet(Hi(MKey),VKKEYSCANCTRLON)) then
                    SendKeyDown(VK_CONTROL,1,False);
                    If (BitSet(Hi(MKey),VKKEYSCANALTON)) then SendKeyDown(VK_MENU,1,False);
                    SendKeyDown(Lo(MKey), NumTimes, GenDownMsg);
                    If (BitSet(Hi(MKey),VKKEYSCANSHIFTON)) then SendKeyUp(VK_SHIFT);
                    If (BitSet(Hi(MKey),VKKEYSCANCTRLON)) then SendKeyUp(VK_CONTROL);
                    If (BitSet(Hi(MKey),VKKEYSCANALTON)) then SendKeyUp(VK_MENU);
                    end;

                    {Implements a simple binary search to locate special key name strings}

                    Function StringToVKey(KeyString : ShortString) : Word;
                    var
                    Found, Collided : Boolean;
                    Bottom, Top, Middle : Byte;
                    begin
                    Result:=INVALIDKEY;
                    Bottom:=1;
                    Top:=MaxSendKeyRecs;
                    Found:=false;
                    Middle:=(Bottom+Top) div 2;
                    Repeat
                    Collided:=((Bottom=Middle) or (Top=Middle));
                    If (KeyString=SendKeyRecs[Middle].Name) then begin
                    Found:=True;
                    Result:=SendKeyRecs[Middle].VKey;
                    end else begin
                    If (KeyString>SendKeyRecs[Middle].Name) then Bottom:=Middle
                    else Top:=Middle;
                    Middle:=(Succ(Bottom+Top)) div 2;
                    end;
                    Until (Found or Collided);
                    If (Result=INVALIDKEY) then DisplayMessage('Invalid Key Name');
                    end;

                    procedure PopUpShiftKeys;
                    begin
                    If (not UsingParens) then begin
                    If ShiftDown then SendKeyUp(VK_SHIFT);
                    If ControlDown then SendKeyUp(VK_CONTROL);
                    If AltDown then SendKeyUp(VK_MENU);
                    ShiftDown:=false;
                    ControlDown:=false;
                    AltDown:=false;
                    end;
                    end;

                    begin
                    AllocationSize:=MaxInt;
                    Result:=false;
                    UsingParens:=false;
                    ShiftDown:=false;
                    ControlDown:=false;
                    AltDown:=false;
                    I:=0;
                    L:=StrLen(SendKeysString);
                    If (L>AllocationSize) then L:=AllocationSize;
                    If (L=0) then Exit;

                    While (I<L) do begin
                    case SendKeysString[I] of
                    '(' : begin
                    UsingParens:=True;
                    Inc(I);
                    end;
                    ')' : begin
                    UsingParens:=False;
                    PopUpShiftKeys;
                    Inc(I);
                    end;
                    '%' : begin
                    AltDown:=True;
                    SendKeyDown(VK_MENU,1,False);
                    Inc(I);
                    end;
                    '+' : begin
                    ShiftDown:=True;
                    SendKeyDown(VK_SHIFT,1,False);
                    Inc(I);
                    end;
                    '^' : begin
                    ControlDown:=True;
                    SendKeyDown(VK_CONTROL,1,False);
                    Inc(I);
                    end;
                    '{' : begin
                    NumTimes:=1;
                    If (SendKeysString[Succ(I)]='{') then begin
                    MKey:=VK_LEFTBRACKET;
                    SetBit(Wbytes(MKey)[1],VKKEYSCANSHIFTON);
                    SendKey(MKey,1,True);
                    PopUpShiftKeys;
                    Inc(I,3);
                    Continue;
                    end;
                    KeyString:='';
                    FoundClose:=False;
                    While (I<=L) do begin
                    Inc(I);
                    If (SendKeysString[I]='}') then begin
                    FoundClose:=True;
                    Inc(I);
                    Break;
                    end;
                    KeyString:=KeyString+Upcase(SendKeysString[I]);
                    end;
                    If (Not FoundClose) then begin
                    DisplayMessage('No Close');
                    Exit;
                    end;
                    If (SendKeysString[I]='}') then begin
                    MKey:=VK_RIGHTBRACKET;
                    SetBit(Wbytes(MKey)[1],VKKEYSCANSHIFTON);
                    SendKey(MKey,1,True);
                    PopUpShiftKeys;
                    Inc(I);
                    Continue;
                    end;
                    PosSpace:=Pos(' ',KeyString);
                    If (PosSpace<>0) then begin

                    NumTimes:=StrToInt(Copy(KeyString,Succ(PosSpace),Length(KeyString)-PosSpace)
                    );
                    KeyString:=Copy(KeyString,1,Pred(PosSpace));
                    end;
                    If (Length(KeyString)=1) then MKey:=vkKeyScan(KeyString[1])
                    else MKey:=StringToVKey(KeyString);
                    If (MKey<>INVALIDKEY) then begin
                    SendKey(MKey,NumTimes,True);
                    PopUpShiftKeys;
                    Continue;
                    end;
                    end;
                    '~' : begin
                    SendKeyDown(VK_RETURN,1,True);
                    PopUpShiftKeys;
                    Inc(I);
                    end;
                    else begin
                    MKey:=vkKeyScan(SendKeysString[I]);
                    If (MKey<>INVALIDKEY) then begin
                    SendKey(MKey,1,True);
                    PopUpShiftKeys;
                    end else DisplayMessage('Invalid KeyName');
                    Inc(I);
                    end;
                    end;
                    end;
                    Result:=true;
                    PopUpShiftKeys;
                    end;

                    {AppActivate

                    This is used to set the current input focus to a given window using its
                    name. This is especially useful for ensuring a window is active before
                    sending it input messages using the SendKeys function. You can specify
                    a window's name in its entirety, or only portion of it, beginning from
                    the left.

                    }

                    var
                    WindowHandle : HWND;

                    function EnumWindowsProc(WHandle: HWND; lParam: LPARAM): BOOL; export;
                    stdcall;
                    const
                    MAX_WINDOW_NAME_LEN = 80;
                    var
                    WindowName : array[0..MAX_WINDOW_NAME_LEN] of char;
                    begin
                    {Can't test GetWindowText's return value since some windows don't have a
                    title}
                    GetWindowText(WHandle,WindowName,MAX_WINDOW_NAME_LEN);
                    Result := (StrLIComp(WindowName,PChar(lParam), StrLen(PChar(lParam))) <>
                    0);
                    If (not Result) then WindowHandle:=WHandle;
                    end;

                    function AppActivate(WindowName : PChar) : boolean;
                    begin
                    try
                    Result:=true;
                    WindowHandle:=FindWindow(nil,WindowName);
                    If (WindowHandle=0) then
                    EnumWindows(@EnumWindowsProc,Integer(PChar(WindowName)));
                    If (WindowHandle<>0) then begin
                    SendMessage(WindowHandle, WM_SYSCOMMAND, SC_HOTKEY, WindowHandle);
                    SendMessage(WindowHandle, WM_SYSCOMMAND, SC_RESTORE, WindowHandle);
                    end else Result:=false;
                    except
                    on Exception do Result:=false;
                    end;
                    end;

                    end.




                    ----- Original Message -----
                    From: "dwolver" <dwolver@...>
                    To: <delphi-webbrowser@yahoogroups.com>
                    Sent: Wednesday, January 29, 2003 8:30 AM
                    Subject: Re: [delphi-webbrowser] Re: Auto form fill


                    > There is a sndkey32.pas file in the Delphi5 cd in one of the extra
                    folders.
                    > I have attached it to this reply, hopefully it shows up.
                    > dale
                    >
                    >
                    >
                    > ----- Original Message -----
                    > From: "Carrz KISS @ Carrz-Fox-Fire Promotions"
                    > <carrzkiss@...>
                    > To: <delphi-webbrowser@yahoogroups.com>
                    > Sent: Wednesday, January 29, 2003 7:55 AM
                    > Subject: Re: [delphi-webbrowser] Re: Auto form fill
                    >
                    >
                    >
                    > [Non-text portions of this message have been removed]
                    >
                    >
                    > Subscribe: delphi-webbrowser-subscribe@yahoogroups.com
                    > Unsubscribe: delphi-webbrowser-unsubscribe@yahoogroups.com
                    > List owner: delphi-webbrowser-owner@yahoogroups.com
                    >
                    >
                    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
                    >
                    >
                  • Carrz KISS @ Carrz-Fox-Fire Promotions
                    Thank you dwolver ; have it compiled and added into uses. , sndkey32; Now to get rid of a few errors, and test this code to see if it will do What I
                    Message 9 of 13 , Jan 29, 2003
                    • 0 Attachment
                      Thank you "dwolver";

                      have it compiled and added into uses. ", sndkey32; "
                      Now to get rid of a few errors, and test this code to see if it will
                      do "What I hoooope!" it will do for my issue.

                      Take Care
                      Wayne
                    • Carrz KISS @ Carrz-Fox-Fire Promotions
                      ... I am getting the following error, that I do not quite understand why? And how to fix. Could someone please tell me if there is a work around, or what I am
                      Message 10 of 13 , Jan 29, 2003
                      • 0 Attachment
                        >
                        > > > for I:=0 to WebBrowser1.OleObject.Document.forms.Length -1 do
                        > > > begin
                        > > > FormItem := WebBrowser1.OleObject.Document.forms.Item(I);
                        > > > For j:= 0 to FormItem.Length-1 do
                        > > > begin
                        > > > try
                        > > > if (FormItem.Item(j).Name = 'myfileinput')
                        > > > and (uppercase(FormItem.Item(j).type) = 'FILE')
                        > > > then begin
                        > > > FormItem.Item(j).focus;
                        > > > Sendkeys(Edit4.Text);
                        > > > end;
                        > > > except
                        > > > exit;
                        > > > end;
                        > > > end;
                        > > > end;
                        > > >
                        >
                        I am getting the following error, that I do not quite understand why? And
                        how to fix.
                        Could someone please tell me if there is a work around, or what I am missing
                        in
                        Delphi 6.02 Pro....

                        [Error] EBAY.pas(808): Incompatible types: 'TCaption' and 'PChar'

                        It is on the line

                        > > > Sendkeys(Edit4.Text);

                        This is what the full code looks like, As it is using the above code mixed
                        with the code that I am
                        already using.


                        // ===================================================
                        var
                        i, j: Integer;
                        FormItem: Variant;
                        begin
                        Result := False;
                        // no form on document
                        if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
                        begin
                        Exit;
                        end;
                        // count forms on document
                        for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
                        begin
                        FormItem := WebBrowser.OleObject.Document.forms.Item(I);
                        for j := 0 to FormItem.Length - 1 do
                        begin
                        try
                        // when the fieldname is found, try to fill out
                        if FormItem.Item(j).Name = FieldName then
                        if (FormItem.Item(j).Name = 'password')
                        and (uppercase(FormItem.Item(j).type) = 'FILE')
                        then begin
                        FormItem.Item(j).Value := Value;
                        Result := True;
                        FormItem.Item(j).focus;
                        Sendkeys(edit4.Text);
                        end;
                        except
                        Exit;
                        end;
                        end;
                        end;
                        end;
                        // ===================================================


                        Thank you
                        Wayne
                      • dalewolver <dwolver@telusplanet.net>
                        By the looks of your code you are not trying to set a file input property but possibly a password field. Is this correct? For setting normal fields I think
                        Message 11 of 13 , Jan 30, 2003
                        • 0 Attachment
                          By the looks of your code you are not trying to set a file input
                          property but possibly a password field. Is this correct?
                          For setting normal fields I "think" you can get away with code that
                          will set the text of a specific field like this:

                          function FillForm(WebBrowser: TWebBrowser; FieldName: string; Value:
                          string): Boolean;
                          var
                          i, j: Integer;
                          FormItem: Variant;
                          begin
                          Result := False;
                          //no form on document
                          if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
                          begin
                          Exit;
                          end;
                          //count forms on document
                          for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
                          begin
                          FormItem := WebBrowser.OleObject.Document.forms.Item(I);
                          for j := 0 to FormItem.Length - 1 do
                          begin
                          try
                          //when the fieldname is found, try to fill out
                          if FormItem.Item(j).Name = FieldName then
                          begin
                          FormItem.Item(j).Value := Value;
                          Result := True;
                          end;
                          except
                          Exit;
                          end;
                          end;
                          end;
                          end;//FillForm


                          If however you are trying to set a read-only field using the SendKeys
                          command, specifically the sndkey32.pas file I put up here yesterday,
                          you will need to look at the SendKeys function in there as it has
                          different paramaters from the one the other user sent. It requires a
                          boolean set as well. Here is my code for setting a File input field
                          named file1.


                          procedure TfrmWtcUploader.SetFilename(Value: WideString);
                          var
                          Doc: IHTMLDocument2;
                          Elements: IHTMLElementCollection;
                          Element: IHTMLElement;
                          InputElement: IHTMLInputElement;
                          I,j: Integer;
                          FormItem: Variant;
                          pch: PChar;
                          str1: string;
                          (*
                          Jan27.03 At long last here is how to automate a file input box.
                          *)
                          begin
                          str1:= Value;//convert input value to string
                          pch := PChar(str1);//type cast to pointer

                          Doc := WebBrowser1.Document as IHTMLDocument2;
                          Elements := Doc.all;
                          for I := 0 to Elements.length - 1 do
                          begin
                          Element := Elements.item(I, EmptyParam) as IHtmlElement;
                          if Element.tagName = 'INPUT' then
                          begin
                          InputElement := Element as IHTMLInputElement;
                          if (SameText(InputElement.type_,'file')) and
                          (SameText(InputElement.Name, 'file1'))then
                          begin
                          FormItem:= InputElement;
                          FormItem.Focus;
                          SendKeys(PCh,False);// NOTE the false flag
                          end;
                          end;
                          end;
                          end;//SetFilename






                          > I am getting the following error, that I do not quite understand
                          why? And
                          > how to fix.
                          > Could someone please tell me if there is a work around, or what I
                          am missing
                          > in
                          > Delphi 6.02 Pro....
                          >
                          > [Error] EBAY.pas(808): Incompatible types: 'TCaption' and 'PChar'
                          >
                          > It is on the line
                          >
                          > > > > Sendkeys(Edit4.Text);
                          >
                          > This is what the full code looks like, As it is using the above
                          code mixed
                          > with the code that I am
                          > already using.
                          >
                          >
                          > // ===================================================
                          > var
                          > i, j: Integer;
                          > FormItem: Variant;
                          > begin
                          > Result := False;
                          > // no form on document
                          > if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
                          > begin
                          > Exit;
                          > end;
                          > // count forms on document
                          > for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
                          > begin
                          > FormItem := WebBrowser.OleObject.Document.forms.Item(I);
                          > for j := 0 to FormItem.Length - 1 do
                          > begin
                          > try
                          > // when the fieldname is found, try to fill out
                          > if FormItem.Item(j).Name = FieldName then
                          > if (FormItem.Item(j).Name = 'password')
                          > and (uppercase(FormItem.Item(j).type) = 'FILE')
                          > then begin
                          > FormItem.Item(j).Value := Value;
                          > Result := True;
                          > FormItem.Item(j).focus;
                          > Sendkeys(edit4.Text);
                          > end;
                          > except
                          > Exit;
                          > end;
                          > end;
                          > end;
                          > end;
                          > // ===================================================
                          >
                          >
                          > Thank you
                          > Wayne
                        • Ahmed Elanabi
                          the problem in sendkey parameter it must be pchar not string try this one sendkey(pchar(edit4.text)); ... I am getting the following error, that I do not quite
                          Message 12 of 13 , Feb 8, 2003
                          • 0 Attachment
                            the problem in sendkey parameter
                            it must be pchar not string
                            try this one
                            sendkey(pchar(edit4.text));
                            "Carrz KISS @ Carrz-Fox-Fire Promotions" <carrzkiss@...> wrote:

                            >
                            > > > for I:=0 to WebBrowser1.OleObject.Document.forms.Length -1 do
                            > > > begin
                            > > > FormItem := WebBrowser1.OleObject.Document.forms.Item(I);
                            > > > For j:= 0 to FormItem.Length-1 do
                            > > > begin
                            > > > try
                            > > > if (FormItem.Item(j).Name = 'myfileinput')
                            > > > and (uppercase(FormItem.Item(j).type) = 'FILE')
                            > > > then begin
                            > > > FormItem.Item(j).focus;
                            > > > Sendkeys(Edit4.Text);
                            > > > end;
                            > > > except
                            > > > exit;
                            > > > end;
                            > > > end;
                            > > > end;
                            > > >
                            >
                            I am getting the following error, that I do not quite understand why? And
                            how to fix.
                            Could someone please tell me if there is a work around, or what I am missing
                            in
                            Delphi 6.02 Pro....

                            [Error] EBAY.pas(808): Incompatible types: 'TCaption' and 'PChar'

                            It is on the line

                            > > > Sendkeys(Edit4.Text);

                            This is what the full code looks like, As it is using the above code mixed
                            with the code that I am
                            already using.


                            // ===================================================
                            var
                            i, j: Integer;
                            FormItem: Variant;
                            begin
                            Result := False;
                            // no form on document
                            if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
                            begin
                            Exit;
                            end;
                            // count forms on document
                            for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
                            begin
                            FormItem := WebBrowser.OleObject.Document.forms.Item(I);
                            for j := 0 to FormItem.Length - 1 do
                            begin
                            try
                            // when the fieldname is found, try to fill out
                            if FormItem.Item(j).Name = FieldName then
                            if (FormItem.Item(j).Name = 'password')
                            and (uppercase(FormItem.Item(j).type) = 'FILE')
                            then begin
                            FormItem.Item(j).Value := Value;
                            Result := True;
                            FormItem.Item(j).focus;
                            Sendkeys(edit4.Text);
                            end;
                            except
                            Exit;
                            end;
                            end;
                            end;
                            end;
                            // ===================================================


                            Thank you
                            Wayne




                            Yahoo! Groups SponsorADVERTISEMENT

                            Subscribe: delphi-webbrowser-subscribe@yahoogroups.com
                            Unsubscribe: delphi-webbrowser-unsubscribe@yahoogroups.com
                            List owner: delphi-webbrowser-owner@yahoogroups.com


                            Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



                            ---------------------------------
                            Do you Yahoo!?
                            Yahoo! Mail Plus - Powerful. Affordable. Sign up now

                            [Non-text portions of this message have been removed]
                          • joyoung00
                            I m having a problem with the code also. This is my first attempt at using tWebbrowser or anything to do with the internet and Delphi. I ve learned a lot from
                            Message 13 of 13 , Jan 5, 2004
                            • 0 Attachment
                              I'm having a problem with the code also. This is my first attempt at
                              using tWebbrowser or anything to do with the internet and Delphi.
                              I've learned a lot from reading this forum but I'm really stuck at
                              this point. It inserts the file name just fine but when I continue on
                              to press the upload file button it comes back with a message
                              saying "the file is in an incorrect format or it is not a valid file
                              name". It isn't a problem with the file since I can go upload the
                              file manually by pressing the Browse button on the page, selecting
                              the file from my hard drive in the file dialog, and then pressing the
                              upload file button. I hope someone can tell me what I'm doing wrong.
                              Here is my code:

                              procedure TForm1.Button6Click(Sender: TObject);
                              var
                              (*
                              Jan27.03 At long last here is how to automate a file input box.
                              *)
                              EncodedDataString: string;
                              PostData: OleVariant;
                              FormItem: Variant;
                              Headers: OleVariant;
                              pch: PChar;
                              str1: string;
                              ov : OleVariant;
                              idisp : idispatch;
                              I,j : Integer;
                              Document: Variant;
                              ovElements: OleVariant;
                              begin
                              //********************************* next attempt

                              While WebBrowser1.ReadyState<>READYSTATE_COMPLETE do
                              Application.ProcessMessages;

                              if WebBrowser1.OleObject.Document.all.tags('FORM').Length = 0 then
                              begin
                              Exit;
                              end; //count forms on document
                              for I := 0 to WebBrowser1.OleObject.Document.forms.Length - 1 do
                              begin
                              FormItem := WebBrowser1.OleObject.Document.forms.Item(I);
                              for j := 0 to FormItem.Length - 1 do
                              begin
                              try
                              begin
                              EncodedDataString := FormItem.Item(j).name;
                              if (FormItem.Item(j).Name = 'file_field') and
                              (uppercase(FormItem.Item(j).type) = 'FILE') then
                              begin
                              str1 := 'H:\New Nicl\Alliance\mb4\stub1230A.CSV';
                              pch := PChar(str1);//type cast to pointer
                              FormItem.Item(j).focus;
                              SendKeys(PCh,False);// NOTE the false flag
                              end;
                              // when Submit button is found, try to click
                              if (FormItem.Item(j).type = 'submit') and
                              (FormItem.Item(j).name = 'upload_manager_submit') then
                              begin
                              FormItem.Item(j).Click;
                              madeit := true;
                              end;
                              end
                              except
                              madeit := false;
                              end;
                              end;
                              end;
                              end;

                              --- In delphi-webbrowser@yahoogroups.com, Ahmed Elanabi
                              <el3nabi2003@y...> wrote:
                              >
                              > the problem in sendkey parameter
                              > it must be pchar not string
                              > try this one
                              > sendkey(pchar(edit4.text));
                              > "Carrz KISS @ Carrz-Fox-Fire Promotions" <carrzkiss@c...> wrote:
                              >
                              > >
                              > > > > for I:=0 to WebBrowser1.OleObject.Document.forms.Length -1
                              do
                              > > > > begin
                              > > > > FormItem := WebBrowser1.OleObject.Document.forms.Item(I);
                              > > > > For j:= 0 to FormItem.Length-1 do
                              > > > > begin
                              > > > > try
                              > > > > if (FormItem.Item(j).Name = 'myfileinput')
                              > > > > and (uppercase(FormItem.Item(j).type) = 'FILE')
                              > > > > then begin
                              > > > > FormItem.Item(j).focus;
                              > > > > Sendkeys(Edit4.Text);
                              > > > > end;
                              > > > > except
                              > > > > exit;
                              > > > > end;
                              > > > > end;
                              > > > > end;
                              > > > >
                              > >
                              > I am getting the following error, that I do not quite understand
                              why? And
                              > how to fix.
                              > Could someone please tell me if there is a work around, or what I
                              am missing
                              > in
                              > Delphi 6.02 Pro....
                              >
                              > [Error] EBAY.pas(808): Incompatible types: 'TCaption' and 'PChar'
                              >
                              > It is on the line
                              >
                              > > > > Sendkeys(Edit4.Text);
                              >
                              > This is what the full code looks like, As it is using the above
                              code mixed
                              > with the code that I am
                              > already using.
                              >
                              >
                              > // ===================================================
                              > var
                              > i, j: Integer;
                              > FormItem: Variant;
                              > begin
                              > Result := False;
                              > // no form on document
                              > if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
                              > begin
                              > Exit;
                              > end;
                              > // count forms on document
                              > for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
                              > begin
                              > FormItem := WebBrowser.OleObject.Document.forms.Item(I);
                              > for j := 0 to FormItem.Length - 1 do
                              > begin
                              > try
                              > // when the fieldname is found, try to fill out
                              > if FormItem.Item(j).Name = FieldName then
                              > if (FormItem.Item(j).Name = 'password')
                              > and (uppercase(FormItem.Item(j).type) = 'FILE')
                              > then begin
                              > FormItem.Item(j).Value := Value;
                              > Result := True;
                              > FormItem.Item(j).focus;
                              > Sendkeys(edit4.Text);
                              > end;
                              > except
                              > Exit;
                              > end;
                              > end;
                              > end;
                              > end;
                              > // ===================================================
                              >
                              >
                              > Thank you
                              > Wayne
                              >
                              >
                              >
                              >
                              > Yahoo! Groups SponsorADVERTISEMENT
                              >
                              > Subscribe: delphi-webbrowser-subscribe@yahoogroups.com
                              > Unsubscribe: delphi-webbrowser-unsubscribe@yahoogroups.com
                              > List owner: delphi-webbrowser-owner@yahoogroups.com
                              >
                              >
                              > Your use of Yahoo! Groups is subject to the Yahoo! Terms of
                              Service.
                              >
                              >
                              >
                              > ---------------------------------
                              > Do you Yahoo!?
                              > Yahoo! Mail Plus - Powerful. Affordable. Sign up now
                              >
                              > [Non-text portions of this message have been removed]
                            Your message has been successfully submitted and would be delivered to recipients shortly.