How to find the button with the value "value" on the html page (Webbrowser - Delphi)

I have an html page that has 3 forms with 3 submit buttons. buttons do not have a name, but they matter:

<input type="submit" VALUE="Login">

How can I find this button with my value and click on it ?

thank

+3
source share
2 answers
procedure TForm1.Button1Click(Sender: TObject);
var 
  ovElements: OleVariant; 
  i: Integer; 
begin 
  ovElements := WebBrowser1.OleObject.Document.forms.item(0).elements; 
  for i := 0 to (ovElements.Length - 1) do
    if (ovElements.item(i).tagName = 'INPUT') and
      (ovElements.item(i).type = 'SUBMIT') and
  (ovElements.item(i).Value = 'Login') then
      ovElements.item(i).Click; 
end;
+6
source

In this case, I use my WB_send_Click_by_Value procedure:

procedure WB_send_Click_by_Value(WB: TWebbrowser;form_nr:nativeint;tag,typ,val: string);
var ovElements: OleVariant;
i: Integer;
begin
  ovElements := WB.OleObject.Document.forms.item(form_nr).elements;
  for i := 0 to (ovElements.Length - 1) do
    begin
      if AnsiSameText(ovElements.item(i).tagName,tag) and
         AnsiSameText(ovElements.item(i).type,typ) and
         AnsiSameText(ovElements.item(i).value,val) then
         ovElements.item(i).Click;
    end;
end;

I use this procedure for buttons in WebPage Formular 1, for example:

WB_send_Click_by_Value(Webbrowser1,0,'input','submit','ok');

or, for example, for RadioButtons in form 2, for example:

WB_send_Click_by_Value(Webbrowser1,1,'input','radio','dns');
+1
source

Source: https://habr.com/ru/post/1763437/


All Articles