怎样实现如下的自动功能?(300分)

  • 主题发起人 主题发起人 UnderWyx
  • 开始时间 开始时间
U

UnderWyx

Unregistered / Unconfirmed
GUEST, unregistred user!
一个IE窗口分成上下两层,目的是在上层查找一个写着 s1 的按钮(即caption=s1)并单击,然后在下层找一个写着 s2 的按钮并单击,之后在下层选择一个写着 s3 的单选钮,再单击写着 s4 的按钮即可<br><br>概括一下就是怎样在一个分层的IE窗口中查找 caption值为某字串的按钮和单选钮?
 
哇,没看懂,饶口令一样。
 
是不是多个Frame的间的访问, 跨Frame访问脚本不容易
 
晕,迷糊~<br>
 
出考题?
 
不好意思,偶的语文很差<br>其实就是让程序找一个上面写着“运行”的按钮并单击,然后选择一个写着“ABC”的单选钮
 
网页的程序还是delphi的啊
 
看来我还是没说清楚*_*<br>我想编一个Delphi的程序实现控制IE的功能
 
下面是一个例子:<br>var<br>&nbsp; Document: IHTMLDocument2;<br>&nbsp; Idx: OleVariant;<br>&nbsp; Window: OleVariant;<br>&nbsp; i: Integer;<br>begin<br>&nbsp; Document:=WebBrowser1.Document as IHTMLDocument2;<br>&nbsp; Idx:=0;<br>&nbsp; Window:=Document.frames.item(Idx);<br>&nbsp; for i:=0 to Window.document.all.length-1 do<br>&nbsp; begin<br>&nbsp; //如果预先知道按钮的名字,那么可以直接这样写Window.document.s1.click;<br>&nbsp; &nbsp; if SameText(Window.document.all.item(i).tagName,'input') then<br>&nbsp; &nbsp; &nbsp; if SameText(Window.document.all.item(i).value,'s1') then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Window.document.all.item(i).click;<br>&nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; end;<br><br>&nbsp; Document:=WebBrowser1.Document as IHTMLDocument2;<br>&nbsp; Idx:=1;<br>&nbsp; Window:=Document.frames.item(Idx);<br>&nbsp; for i:=0 to Window.document.all.length-1 do<br>&nbsp; begin<br>&nbsp; &nbsp; if SameText(Window.document.all.item(i).tagName,'input') then<br>&nbsp; &nbsp; &nbsp; if SameText(Window.document.all.item(i).value,'s2') then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Window.document.all.item(i).click;<br>&nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; 。。。<br>end;<br>
 
如果你要直接控制IE,参考下面的链接,获得IHTMLDocument2接口就可以为所欲为了[:)]<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=2146493
 
那个程序我看了,但是我要控制的那个网页无法查看源文件啊,所以按钮和单选钮得自己找,怎么实现?
 
没有查看不了源文件的网页[:)]<br>上面不是已经写出代码了吗?不知道的话就遍历找着它,再执行操作<br>代码基本上和写js是差不多的<br>
 
如果我想直接控制IE,让它找一个“运行”的按钮并单击,程序应该怎样修改?
 
获得IE的IHTMLDocuemnt2接口我就不说了,上面都有写<br>var<br>&nbsp; Document: IHTMLDocument2;<br>&nbsp; Window: OleVariant;<br>begin<br>&nbsp; ...<br>&nbsp; //如果有框架,那么还有找到正确的页面 Window:=Document.frames.item(框架的下标)<br>&nbsp; //否则直接赋值 Window:=Document.parentWindow<br>&nbsp; for i:=0 to Window.document.all.length-1 do<br>&nbsp; begin<br>&nbsp; &nbsp; if SameText(Window.document.all.item(i).tagName,'input') then<br>&nbsp; &nbsp; &nbsp; if SameText(Window.document.all.item(i).value,'运行') then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ShowMessage('找到了');<br>&nbsp; &nbsp; &nbsp; &nbsp; Window.document.all.item(i).click; //点击它<br>&nbsp; &nbsp; &nbsp; &nbsp; Window.document.all.item(i).value='运行 已经找到了'; //改变值<br>&nbsp; &nbsp; &nbsp; &nbsp; //Window.document.all.item(i).check=true; //checkbox类似的判断,给其赋值。。。<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; end;<br>end;
 
这个问题解决了<br>---------------------------<br>我试了一下,访问Google时点击"GOOGLE搜索按钮",但是报错了<br>在 &nbsp; &nbsp; Window:=Document.frames.item(Idx);一行<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp;Document: IHTMLDocument2;<br>&nbsp;Idx: OleVariant;<br>&nbsp;Window: OleVariant;<br>&nbsp;i: Integer;<br>begin<br>&nbsp; &nbsp; &nbsp;Document:=WebBrowser1.Document as IHTMLDocument2;<br>&nbsp; &nbsp; &nbsp;Idx:=0;<br>&nbsp; &nbsp; &nbsp;Window:=Document.frames.item(Idx);<br>&nbsp; &nbsp; &nbsp;for i:=0 to Window.document.all.length-1 do<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;if SameText(Window.document.all.item(i).tagName,'input') then<br>&nbsp; &nbsp; &nbsp; &nbsp;if SameText(Window.document.all.item(i).value,'Google搜索') then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Window.document.all.item(i).click;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; webbrowser1.Navigate('http://www.google.com')<br>end;
 
&gt;&gt; 在 &nbsp; &nbsp; Window:=Document.frames.item(Idx);一行<br>因为网页中没有包含框架<br>if Document.frames.length&gt;0 then<br>&nbsp; ...<br>else<br>&nbsp; Window:=Document.parentWindow;<br>
 
接受答案了.
 
后退
顶部