如何从加载的页面中提取元素 ID



我有一个在TembeddedWb中加载一些页面的项目。加载页面后,我想从一些图像中获取 ID 元素。例如,我在 html 页面中有这样的图像

<a href="#" style="cursor:pointer"><img id="image1" src='pathto/image1' border="0" style="display:inline" /></a>

当我在 tembeddedwb 中单击此图像时,我应该如何读取 ID 元素?

我尝试了这样的事情:

 var
  MousePos: TPoint;
  HtmlElement: IHTMLElement;
  iHTMLDoc: IHtmlDocument2;
edit.Text := edit.text + ' ' + HtmlElement.id;

我必须使用Tpoint吗?我该怎么办?

所以我遵循 TLama 评论,我在这里做到了,这是我为将来帮助他人所做的

var
  MousePos: TPoint;
  HtmlElement: IHTMLElement;
  iHTMLDoc: IHtmlDocument2;
begin
  MousePos := Ewb.ScreenToClient(MousePos);
  HtmlElement := iHTMLDoc.ElementFromPoint(MousePos.X, MousePos.Y);
  if Assigned(HtmlElement) then
    showmessage('id');
end;

最新更新