您的位置:首页 > 其它

Webbrowser判断网页控件是否存在?

2013-03-17 21:59 891 查看
网页代码:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
<script>
function aa(){
alert("abc");
}
</script>
</head>

<body>

<form method="POST" action="--WEBBOT-SELF--">
<p><input type="button" value="按钮" name="B3" onclick="aa()"></p>
</form>

</body>

</html>


delphi判断网页中是否存在某个名字的控件

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls, MSHTML_TLB;

type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Math;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.Navigate('c:\index.htm');
end;

procedure TForm1.Button1Click(Sender: TObject);
var b:IHTMLElement;
begin
b:=(WebBrowser1.Document as IHTMLDocument3).getElementById('B3');
if b=nil then exit;//这里判断网页中是不是找到了这个按钮,如果换成B4就不能执行下面的代码了
b.click;
end;

end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: