TWebBrowser automation problem - code included.

Hi.
Got some code for automated TWebBrowser forms filling, but in some cases it isnt working... any idea why? Getting this error: "method 'name' not supported by automation object" ... and it DOES work in almost every site... but for example not here: http://profil.interia.pl/nowe_konto/

It halts on "WbSetEditField(webbrowser1,'formLogin',login);" for example...

<code>
unit WbCtrl;       

interface       

uses Windows, Classes, Forms, ShDocVw_TLB, WinInet, ActiveX;       

function WbEnumFields(WebBrowser: TWebBrowser; SL: TStrings): Boolean;       
function WbSetEditField(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;       
function WbGetEditField(WebBrowser: TWebBrowser; FieldName: string; var Value: string): Boolean;       
function WbSetCheckBoxField(WebBrowser: TWebBrowser; FieldName: string; Checked: boolean): Boolean;       
function WbGetCheckBoxField(WebBrowser: TWebBrowser; FieldName: string; var Checked: boolean): Boolean;       
function WbBtnClick(WebBrowser: TWebBrowser; FieldName: string): Boolean;
function WbBtnClickByValue(WebBrowser: TWebBrowser; Value: string): Boolean;
function WbBtnSubmitByWidth(WebBrowser: TWebBrowser; ButtonWidth: string): Boolean;
function WbSetEditFieldByNameAndSize(WebBrowser: TWebBrowser; FieldName: string; Size: string; Value: string): Boolean;
function WbBtnClickByValueAndName(WebBrowser: TWebBrowser; Value: string; FName: string): Boolean;

implementation       

// Lese alle Feldnamen aus       
// Übergabe:       
// Webbroweser: Webbrowser, der die aktuelle Seite enthält       
// Sl         : Die Stringlist zu der alle Feldnamen hinzugefügt werden sollen       
// Result     : true  -> Feld existiert       
//            : false -> Feld existiert nicht       
//                       oder kein Dokument geladen       
function WbEnumFields(WebBrowser: TWebBrowser; SL: TStrings): Boolean;       
var       
  i, j: Integer;       
  FormItem: Variant;       
begin       
  Result := True;       
  //Hat das Dokument Forms? (Frames)       
  if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then       
  begin       
    Result := False;       
    Exit;       
  end;       
  //Bearbeite alle Frames       
  for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do       
  begin       
    FormItem := WebBrowser.OleObject.Document.forms.Item(I);       
    // Bearbeite alle Felder eines Frames       
    for j := 0 to FormItem.Length - 1 do       
    begin       
      try       
        SL.Add(FormItem.Item(j).Name);       
      except       
        Result := False;       
        Exit;       
      end;       
    end;       
  end;       
end;       

// Durchsuche alle Formulare im Webbrowser nach dem Feldnamen       
// Übergabe:       
// Webbroweser: Webbrowser, der die aktuelle Seite enthält
// FieldName  : Name des gesuchten Felds
// Rückgabe
// Field      : Field.x : Frame Nummer
//            : Fielf.y : Feld Nummer im Frame
// Result     : true  -> Feld existiert
//            : false -> Feld existiert nicht
//                       oder kein Dokument geladen
function WbFindField(WebBrowser: TWebBrowser; FieldName: string; var Field: TPoint): boolean;
var
  i, j: Integer;       
  FormItem: Variant;
begin       
  Result := False;
  //Hat das Dokument Forms? (Frames)
  if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
  begin
    Exit;
  end;
  //Bearbeite alle Frames
  for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
  begin
    FormItem := WebBrowser.OleObject.Document.forms.Item(I);
    // Bearbeite alle Felder eines Frames
    for j := 0 to FormItem.Length - 1 do
    begin
      try
        // Feldname wurde gefunden
        // gebe ihn zurück und ende
        if FormItem.Item(j).Name = FieldName then
        begin
          Field.x := i;          // Position speichern
          Field.Y := j;
          Result := True;
          exit;
        end;
      except
        Exit;
      end;
    end;
  end;
end;

function WbFindFieldByNameAndSize(WebBrowser: TWebBrowser; FieldName: string; Size: string; var Field: TPoint): boolean;
var
  i, j: Integer;       
  FormItem: Variant;
begin       
  Result := False;
  //Hat das Dokument Forms? (Frames)
  if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
  begin
    Exit;
  end;
  //Bearbeite alle Frames
  for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
  begin
    FormItem := WebBrowser.OleObject.Document.forms.Item(I);
    // Bearbeite alle Felder eines Frames
    for j := 0 to FormItem.Length - 1 do
    begin
      try
        // Feldname wurde gefunden
        // gebe ihn zurück und ende
        if (FormItem.Item(j).Name = FieldName) and (FormItem.Item(j).Size = Size) then
        begin
          Field.x := i;          // Position speichern
          Field.Y := j;
          Result := True;
          exit;
        end;
      except
        Exit;
      end;
    end;
  end;
end;

function WbFindFieldByValue(WebBrowser: TWebBrowser; Value: string; var Field: TPoint): boolean;
var
  i, j: Integer;
  FormItem: Variant;
begin
  Result := False;
  //Hat das Dokument Forms? (Frames)
  if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
  begin
    Exit;
  end;
  //Bearbeite alle Frames
  for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
  begin
    FormItem := WebBrowser.OleObject.Document.forms.Item(I);
    // Bearbeite alle Felder eines Frames
    for j := 0 to FormItem.Length - 1 do
    begin
      try
        // Feldname wurde gefunden
        // gebe ihn zurück und ende
        if pos(Value,FormItem.Item(j).Value) > 0 then
        begin
          Field.x := i;          // Position speichern
          Field.Y := j;
          Result := True;
          exit;       
        end;
      except       
        Exit;
      end;
    end;
  end;
end;

function WbFindFieldByValueAndName(WebBrowser: TWebBrowser; Value: string; FName:string; var Field: TPoint): boolean;
var
  i, j: Integer;
  FormItem: Variant;
begin
  Result := False;
  //Hat das Dokument Forms? (Frames)
  if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
  begin
    Exit;
  end;
  //Bearbeite alle Frames
  for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
  begin
    FormItem := WebBrowser.OleObject.Document.forms.Item(I);
    // Bearbeite alle Felder eines Frames
    for j := 0 to FormItem.Length - 1 do
    begin
      try
        // Feldname wurde gefunden
        // gebe ihn zurück und ende
        if (pos(Value,FormItem.Item(j).Value) > 0) and (FormItem.Item(j).Name = FName) then
        begin
          Field.x := i;          // Position speichern
          Field.Y := j;
          Result := True;
          exit;       
        end;
      except       
        Exit;
      end;
    end;
  end;
end;

function WbFindSubmitByWidth(WebBrowser: TWebBrowser; ButtonWidth: string; var Field: TPoint): boolean;
var       
  i, j: Integer;       
  FormItem: Variant;       
begin       
  Result := False;       
  //Hat das Dokument Forms? (Frames)       
  if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then       
  begin       
    Exit;       
  end;       
  //Bearbeite alle Frames       
  for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do       
  begin       
    FormItem := WebBrowser.OleObject.Document.forms.Item(I);       
    // Bearbeite alle Felder eines Frames       
    for j := 0 to FormItem.Length - 1 do       
    begin       
      try       
        // Feldname wurde gefunden       
        // gebe ihn zurück und ende       
        if (FormItem.Item(j).type = 'submit') and (FormItem.Item(j).width = ButtonWidth) then
        begin       
          Field.x := i;          // Position speichern       
          Field.Y := j;       
          Result := True;       
          exit;       
        end;       
      except       
        Exit;       
      end;       
    end;       
  end;       
end;

// Trage Text in ein Editfeld ein       
// Übergabe:       
// Webbroweser: Webbrowser, der die aktuelle Seite enthält       
// FieldName  : Name des gesuchten Felds       
// Rückgabe       
// Value      : Der Text, der in das Feld hinein soll       
// Result     : true  -> kein Fehler       
//            : false -> Feld existiert nicht       
//                       oder kein Dokument geladen       
function WbSetEditField(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;       
var       
  Field: TPoint;       
begin       
  // Position des Felds holen       
  if not WbFindField(WebBrowser, FieldName, Field) then       
  begin       
    Result := false;  // Feld existiert nicht       
    exit;             // Ende       
  end;       
  try       
    // Feld füllen       
    WebBrowser.OleObject.Document.forms.Item(Field.x).Item(Field.y).Value := Value;       
    Result := True;       
  except       
    Result := false;       
    Exit;       
  end;       
end;

function WbSetEditFieldByNameAndSize(WebBrowser: TWebBrowser; FieldName: string; Size: string; Value: string): Boolean;
var       
  Field: TPoint;       
begin       
  // Position des Felds holen       
  if not WbFindFieldByNameAndSize(WebBrowser, FieldName, Size, Field) then
  begin       
    Result := false;  // Feld existiert nicht       
    exit;             // Ende       
  end;       
  try
    // Feld füllen       
    WebBrowser.OleObject.Document.forms.Item(Field.x).Item(Field.y).Value := Value;       
    Result := True;       
  except       
    Result := false;       
    Exit;       
  end;       
end;

// Lese Text aus einem Editfeld       
// Übergabe:       
// Webbroweser: Webbrowser, der die aktuelle Seite enthält       
// FieldName  : Name des gesuchten Felds       
// Rückgabe       
// Value      : Text, der im Feld steht       
// Result     : true  -> kein Fehler       
//            : false -> Feld existiert nicht       
//                       oder kein Dokument geladen       
function WbGetEditField(WebBrowser: TWebBrowser; FieldName: string; var Value: string): Boolean;       
var       
  Field: TPoint;       
begin       
  // Position des Felds holen       
  if not WbFindField(WebBrowser, FieldName, Field) then       
  begin       
    Result := false;  // Feld existiert nicht       
    exit;             // Ende       
  end;       
  try       
    // Feld lesen       
    Value := WebBrowser.OleObject.Document.forms.Item(Field.x).Item(Field.y).Value;       
    Result := True;       
  except       
    Result := false;       
    Exit;       
  end;       
end;       

// Setze eine Checkbox       
// Übergabe:       
// Webbroweser: Webbrowser, der die aktuelle Seite enthält       
// FieldName  : Name des gesuchten Felds       
// Rückgabe       
// Checked    : Zustand       
// Result     : true  -> kein Fehler       
//            : false -> Feld existiert nicht       
//                       oder kein Dokument geladen       
function WbSetCheckBoxField(WebBrowser: TWebBrowser; FieldName: string; Checked: boolean): Boolean;       
var       
  Field: TPoint;       
begin       
  // Position des Felds holen       
  if not WbFindField(WebBrowser, FieldName, Field) then       
  begin       
    Result := false;  // Feld existiert nicht       
    exit;             // Ende       
  end;       
  try       
    // CheckBox setzen       
    WebBrowser.OleObject.Document.forms.Item(Field.x).Item(Field.y).Checked := Checked;       
    Result := True;       
  except       
    Result := false;       
    Exit;       
  end;       
end;       

// Lese eine Checkbox       
// Übergabe:       
// Webbroweser: Webbrowser, der die aktuelle Seite enthält       
// FieldName  : Name des gesuchten Felds       
// Rückgabe       
// Checked    : Zustand       
// Result     : true  -> kein Fehler       
//            : false -> Feld existiert nicht       
//                       oder kein Dokument geladen       
function WbGetCheckBoxField(WebBrowser: TWebBrowser; FieldName: string; var Checked: boolean): Boolean;       
var       
  Field: TPoint;       
begin       
  // Position des Felds holen       
  if not WbFindField(WebBrowser, FieldName, Field) then       
  begin       
    Result := false;  // Feld existiert nicht       
    exit;             // Ende       
  end;       
  try       
    // CheckBox setzen       
    Checked := WebBrowser.OleObject.Document.forms.Item(Field.x).Item(Field.y).Checked;       
    Result := True;       
  except       
    Result := false;       
    Exit;       
  end;       
end;       

// Click einen Button       
// Übergabe:       
// Webbroweser: Webbrowser, der die aktuelle Seite enthält       
// FieldName  : Name des Button       
// Rückgabe       
// Result     : true  -> kein Fehler       
//            : false -> Feld existiert nicht       
//                       oder kein Dokument geladen       
function WbBtnClick(WebBrowser: TWebBrowser; FieldName: string): Boolean;
var
  Field: TPoint;
begin
  // Position des Felds holen
  if not WbFindField(WebBrowser, FieldName, Field) then
  begin
    Result := false;  // Feld existiert nicht
    exit;             // Ende
  end;
  try       
    // CheckBox setzen
    WebBrowser.OleObject.Document.forms.Item(Field.x).Item(Field.y).Click;
    Result := True;       
  except
    Result := false;       
    Exit;
  end;
end;

function WbBtnClickByValue(WebBrowser: TWebBrowser; Value: string): Boolean;
var
  Field: TPoint;
begin
  // Position des Felds holen
  if not WbFindFieldByValue(WebBrowser, Value, Field) then
  begin
    Result := false;  // Feld existiert nicht
    exit;             // Ende
  end;
  try
    // CheckBox setzen
    WebBrowser.OleObject.Document.forms.Item(Field.x).Item(Field.y).Click;
    Result := True;
  except
    Result := false;
    Exit;
  end;
end;

function WbBtnClickByValueAndName(WebBrowser: TWebBrowser; Value: string; FName: string): Boolean;
var
  Field: TPoint;
begin
  // Position des Felds holen
  if not WbFindFieldByValueAndName(WebBrowser, Value, FName, Field) then
  begin
    Result := false;  // Feld existiert nicht
    exit;             // Ende
  end;
  try
    // CheckBox setzen
    WebBrowser.OleObject.Document.forms.Item(Field.x).Item(Field.y).Click;
    Result := True;
  except
    Result := false;
    Exit;
  end;
end;

function WbBtnSubmitByWidth(WebBrowser: TWebBrowser; ButtonWidth: string): Boolean;
var
  Field: TPoint;
begin
  // Position des Felds holen
  if not WbFindSubmitByWidth(WebBrowser, ButtonWidth, Field) then
  begin
    Result := false;  // Feld existiert nicht
    exit;             // Ende
  end;
  try
    // CheckBox setzen
    WebBrowser.OleObject.Document.forms.Item(Field.x).Item(Field.y).Click;
    Result := True;
  except
    Result := false;
    Exit;
  end;
end;



end.
</code>
LVL 3
flashtAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Eddie ShipmanAll-around developerCommented:
Using the element's "location" on the web form is problematic.
It is best to just use the element's name or id. Use the technique
I outline here and you will be more successful:
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21814080.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eddie ShipmanAll-around developerCommented:
flasht,
  What is the status of this question? Did you try my suggestion? Do you need more help?
0
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.