Witam
Znalazłem w necie przykład symulacji naciśnięcia klawisza na formularzu pobranym ze strony www. Tutaj autor koncentrował się na symulacji naciśnięcia klawisza
unit web;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, MSHTML, StdCtrls, ExtCtrls;
type
TForm5 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
Panel1: TPanel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form5: TForm5;
implementation
{$R *.dfm}
procedure TForm5.Button1Click(Sender: TObject);
var
doc: IHtmlDocument2;
i: integer;
ov: OleVariant;
disp: IDispatch;
collection: IHTMLElementCollection;
inputelement: HTMLInputImage;
begin
WebBrowser1.ControlInterface.Document.QueryInterface(IHtmlDocument2, doc);
if not Assigned(doc) then
begin
Exit;
end;
ov := 'INPUT';
disp := doc.all.tags(ov);
if Assigned(disp) then
begin
disp.QueryInterface(IHTMLElementCollection, collection);
if Assigned(collection) then
begin
for i := 1 to collection.Get_length do
begin
disp := collection.item(pred(i), 0);
disp.QueryInterface(HTMLInputImage, inputelement);
if Assigned(inputelement) then
begin
if inputelement.Name = 'oText' then
=========>tu chcę podstawić odpowiednią wartość Value='cośtam';
if inputelement.Name = 'submit' then
begin
inputelement.Click;
end;
end;
end;
end;
end;
end;
procedure TForm5.FormCreate(Sender: TObject);
var Url, Flags, TargetFrameName, PostData, Headers: OleVariant;
begin
Url := ExtractFilePath(Application.ExeName) + 'Test.htm';
WebBrowser1.Navigate2(Url, Flags, TargetFrameName, PostData, Headers);
end;
end.
<HTML>
<HEAD>
<meta content="JavaScript" name="vs_defaultClientScript">
</HEAD>
<body style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Verdana; TEXT-DECORATION: none">
<form id="Form1" method="post">
<INPUT id="oText" style="Z-INDEX: 101; LEFT: 25px; WIDTH: 206px; FONT-FAMILY: Verdana;
POSITION: absolute" type="text" name="oText" **foo**value="TWÓJ LOGIN" size="29">
<DIV style="DISPLAY: inline; Z-INDEX: 102; LEFT: 23px; WIDTH: 461px; POSITION: absolute; TOP:
24px; HEIGHT: 25px" ms_positioning="FlowLayout">
</DIV>
<INPUT id="submit" style="Z-INDEX: 103; LEFT: 25px; WIDTH: 143px; POSITION: absolute; Top:50px"
type="submit" value="sSubmit" name="submit">
<DIV style="DISPLAY: inline; Z-INDEX: 104; LEFT: 28px; WIDTH: 268px; POSITION: absolute; TOP:
78px; HEIGHT: 22px" ms_positioning="FlowLayout">
</DIV>
</form>
</body>
Ja chciałbym dodatkowo modyfikować zawartość strony, podstawiając odpowiednie wartości pod logowanie, a potem głębiej - inne kontrolki. Czy można się dostać do zawartości i zmienić value="TWÓJ LOGIN" wewnątrz komponentu (inputelement.???), czy trzeba wygenerować kod, zapisać do pliku i wtedy czytywać do WebBrowsera i wysyłać symulując kliknięcie?