1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
| function RemplisFormulaire2(navigateur:twebbrowser;informations:string):boolean;
//informations contient les chaines séparé par #13
//Chaque mot est séparé par des espaces
var
i,j,k: Integer;
FormItem: Variant;
l,m:tstringlist;
begin
Result := informations='';
if result then exit;
if (navigateur.OleObject.Document.all.tags('FORM').Length = 0) and
(navigateur.OleObject.Document.all.tags('form').Length = 0)
then Exit; //no form on document
l:=tstringlist.create;l.text:=informations;
m:=tstringlist.create;m.delimiter:=',';
//count forms on document
for I := 0 to navigateur.OleObject.Document.forms.Length - 1 do begin
FormItem := navigateur.OleObject.Document.forms.Item(I);
for j := 0 to l.count-1 do begin
m.delimitedtext:=l[j];
for k:=0 to FormItem.Length - 1 do if m.count>1 then try
if (FormItem.Item(k).id = m[0]) or (FormItem.Item(k).name = m[0]) then begin
FormItem.Item(k).Value :=m[1];
result:=true;//si on rempli au moin une case c'est bon
end;
except
l.free;
m.free;
exit;
end;
end;
end;
l.free;
m.free;
end;
function RemplisFormulaire(navigateur:twebbrowser;informations:string):boolean;
//informations contient les chaines séparé par #13
//Chaque mot est séparé par des espaces
var
i,j,k,ii: Integer;
FormItem: Variant;
l,m:tstringlist;
begin
Result := informations='';
if result then exit;
if (navigateur.OleObject.Document.all.tags('FORM').Length = 0) and
(navigateur.OleObject.Document.all.tags('form').Length = 0)
then Exit; //no form on document
l:=tstringlist.create;l.text:=informations;
m:=tstringlist.create;m.delimiter:=',';
//count forms on document
for I := 0 to navigateur.OleObject.Document.forms.Length - 1 do begin
FormItem := navigateur.OleObject.Document.forms.Item(I);
for j := 0 to l.count-1 do begin //tout les champs a remplir
m.delimitedtext:=l[j];
for k:=0 to FormItem.Length - 1 do if m.count>1 then try
for ii:=0 to m.count-2 do if (FormItem.Item(k).id = m[ii]) or (FormItem.Item(k).name = m[i]) then begin
FormItem.Item(k).Value :=m[m.count-1];
result:=true;//si on rempli au moin une case c'est bon
break;//termine la boucle ii car succèes
end;
except
l.free;
m.free;
exit;
end;
end;
end;
l.free;
m.free;
end;
function CliqueFormulaireHTML(navigateur:twebbrowser;informations:string):boolean;
var
doc : ihtmldocument2;
Collection : IHTMLElementCollection;
IDP : IDispatch;
i : integer;
InputButton : HTMLInputButtonElement;
l:tstringlist;
begin
result:=false;
l:=tstringlist.create;l.DelimitedText:=informations;
doc := (navigateur.document as ihtmldocument2);
if Assigned(doc) then begin
IDP := Doc.all.tags('input');
if Assigned(IDP) then begin
IDP.QueryInterface(IHTMLElementCollection, Collection);
if Assigned(Collection) then begin
for i := 0 to Collection.Get_length-1 do begin
IDP:= Collection.item(i, 0);
IDP.QueryInterface(HTMLInputButtonElement{HTMLInputImage{}, InputButton);
if (InputButton.Name = l[0]) or (InputButton.Id = l[0]) then begin
InputButton.Click;
result:=true;
break;
end;
end;
end;
end;
end;
l.free;
end;
function CliqueLien(navigateur:twebbrowser;informations:string):boolean;
var
i: integer;
ovLinks: OleVariant;
l:tstringlist;
begin
result:=false;
l:=tstringlist.create;l.DelimitedText:=informations;
ovLinks := navigateur.OleObject.Document.all.tags('A');//extrait les liens
if ovLinks.Length > 0 then begin
for i := 0 to ovLinks.Length-1 do begin
if Pos(l[0], ovLinks.Item(i).href) > 0 then begin
ovLinks.Item(i).click;
Break;
end;
end;
end;
l.free;
end;
function CliqueFormulaireJavaScript(navigateur:twebbrowser;informations:string):boolean;
var l:tstringlist;
//s:string;
iWindow : IHTMLWindow2;
iDoc : IHTMLDocument2;
begin
result:=false;
iDoc := navigateur.Document as IHTMLDocument2;
if not Assigned(iDoc) then Exit;
l:=tstringlist.create;
l.Text:=informations;
try
iWindow := iDoc.parentWindow;
iWindow.execScript('javascript:document.getElementById(' + QuotedStr(l[0]) + ').click();', 'javascript');
result:=true;
except
end;
l.free;
end;
function RemplisEtCliqueFormulaire(navigateur:twebbrowser;informations:string):boolean;
var l:tstringlist;s:string;
begin
l:=tstringlist.create;
l.Text:=informations;
result:=false;
try
s:=l[l.count-1];
l.Delete(l.count-1);
if RemplisFormulaire(navigateur,l.Text) then
if cliquelien(navigateur,s) then result:=true else
if CliqueFormulairehtml(navigateur,s) then result:=true else
if CliqueFormulaireJavaScript(navigateur,s) then result:=true;
except
result:=false;
end;
l.free;
end; |
Partager