如何解决Delphi 10.3-比较IHTMLElements
我正在尝试为在TWebBrowser内的网站上单击(例如)的元素构建XPath。 如果您知道一些可用的功能或其他方式,请给我提示。
procedure TForm1.Button2Click(Sender: TObject);
var
Elem: IHTMLElement;
ss: string;
ii: Integer;
function GetElemOrder(e: IHTMLElement): integer;
var
jj: Integer;
ee: IHTMLElement;
Coll: IHTMLElementCollection;
begin
//get all children of the elem parent - the elem is a child itself
Coll := e.parentElement.children as IHTMLElementCollection;
//filter the tags to minimize the list (only the same tags as the elem)
Coll := Coll.tags(e.tagName) as IHTMLElementCollection;
for jj := 0 to Coll.length - 1 do begin
inc(Result);
ee := Coll.item(jj,EmptyParam) as IHTMLElement;
//go through the list and check if the elem was found
if (e = ee) then // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< this doesn't work
//return the actual count
Exit;
end;
Result := 0; // result 0 means always an error,as the elem wasn't found in the collection
end;
begin
//get element obj
Elem := GetElementById(wb.Document,'input_username') as IHTMLElement;
if Assigned(Elem) then
//build the xpath until reach the root
while elem.parentElement <> nil do begin
// get the order of the elem in the list of children e.g. 3rd DIV from 5 DIVs
ii := GetElemOrder(Elem);
ss := '/' + Elem.tagName + '[' + ii.ToString + ']' + ss;
//go to the next level
Elem := Elem.parentElement;
end;
end;
到目前为止,它仍然有效,但是我无法比较2个IHTMLElements。我在做什么错了?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。