I have the following code:
procedure TMainForm.ValidarAcesso;
var
doc: variant;
element: variant;
begin
doc := coHTMLDocument.Create as IHTMLDocument2;
doc.write(memHtml.Text);
try
element := doc.getElementById('theElementId');
if VarToStr(element) <> '' then
ShowMessage(element.innerText)
else
ShowMessage('Acesso realizado com sucesso!');
except
end;
end;
I create a COM HTML Document and load the Html source of a page in it and then search for an html element using getElementById. This Works!
But how do I add a control to see if the element really exists / was found on the / html page?
When the element is not found, by hovering over the element variable, Delphi displays the value $00000000
.
I've already tested:
VarToStr(element) <> ''
element <> $00000000
VarType(element) ...
element <> null
element <> nil
But none of them worked!