有时候需要模拟点击js链接,但又无name无id该怎么办呢!
用下面代码可以达到意想不到的效果,循环检测链接地址,地址匹配则点击!
procedure TForm1.Button1Click(Sender: TObject); var I: Integer; Document: IHTMLDocument2; Element: IHTMLElement; Anchors: IHTMLElementCollection; sLink: string; begin web2.Navigate('http://www.999999.com/online_info.php?id=2421'); delay(5000); //查找页面链接 sLink := 'javascript:void(0);'; Document := Web2.Document as IHTMLDocument2; if Assigned(Document) then begin Anchors := Document.Get_links; //遍历所有链接 for i := 0 to Anchors.length - 1 do begin Element := Anchors.item(i, varempty) as IHTMLElement; //找到指定链接 if Assigned(Element) and (UpperCase((Element as IHTMLAnchorElement).href) = UpperCase(sLink)) then begin //执行点击 Element.Click; end; end; end; end;
标签:delphi
发表评论