Fórum pegando campo com webbrowser #553511
08/05/2016
0
Boa tarde companheiros, estou a uns dias tentando pegar um campo de uma página web pra ser preenchido por um edit, mas estou enfrentando algumas dificuldades, tentei pegar o campo com esse código mas só que da acess violation, até porque o id do campo está em uma div e não em um input, e outra na mesma linha onde tem o id também tem classes, eu gostaria que alguem me ajudasse a pegar esse campo, vale lembrar também que tenho uma função pra pegar e clicar em um botão de uma página que só tenha classe, tentei pegar o campo com essa função e também não consegui, a função é essa
Se alguém poder me ajudar agradeço desde já, obrigado.
webbrowser6.OleObject.Document.All.tags('input').item('user').value:='edit2.text';
webbrowser6.OleObject.Document.All.tags('input').item('pass').value:= ' unction TForm1.GetElementById(const Doc: IDispatch; const Id: string): IDispatch;
var
Document: IHTMLDocument2; // IHTMLDocument2 interface of Doc
Body: IHTMLElement2; // document body element
Tags: IHTMLElementCollection; // all tags in document body
Tag: IHTMLElement; // a tag in document body
I: Integer; // loops thru tags in document body
begin
Result := nil; // Check for valid document: require IHTMLDocument2 interface to it
if not Supports(Doc, IHTMLDocument2, Document) then
raise Exception.Create('Invalid HTML document'); // Check for valid body element: require IHTMLElement2 interface to it
if not Supports(Document.body, IHTMLElement2, Body) then
raise Exception.Create('Can''t find <body> element'); // Get all tags in body element ('*' => any tag name)
Tags := Body.getElementsByTagName('*'); // Scan through all tags in body
for I := 0 to Pred(Tags.length) do
begin // Get reference to a tag
Tag := Tags.item(I, EmptyParam) as IHTMLElement; // Check tag's id and return it if id matches
if AnsiSameText(Tag.ClassName, Id) then
begin
Result := Tag;
Break;
end;
end;
end;var Elem: IHTMLElement; begin Elem := GetElementById(WebBrowser1.Document, 'sendButton') as IHTMLElement; if Assigned(Elem) then Elem.Click; end;
Se alguém poder me ajudar agradeço desde já, obrigado.
Alex
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)