andersoncamargo1 Novato
Registrado: Sexta-Feira, 15 de Dezembro de 2017 Mensagens: 10
|
Enviada: Qui Abr 26, 2018 11:30 am Assunto: Ajuda com código |
|
|
Eu tenho a seguinte função:
Código: |
function GetElementById(const Doc: IDispatch; const Id: string): IDispatch;
// -- Clica em elementos do html
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.tagName, Id) then
begin
Result := Tag;
Break;
end
else
begin
if AnsiSameText(Tag.Id, Id) then
begin
Result := Tag;
Break;
end;
end;
end;
end;
|
Que esta sendo usada da seguinte maneira;
Código: |
Elem := GetElementById(NavegadorPostagem.Document, 'textarea')as IHTMLElement;
if Assigned(Elem) then
codigo....
|
Desta forma eu posso encontrar e clicar, escrever e etc em um textarea ou outra tag, classe, id etc.
Mas como esta consigo clicar em apenas um, o que quero é adaptar o código para que enquanto tiver a tag textarea ele faça o que foi solicitado, consiga pegar todos os textarea que existir... Sei que tem que ser em um laço, mas não sei como adaptar. |
|