如何实现点击页面中的所有link
Dim oDesc,colObjectSet oDesc = Description.Create
oDesc( "micclass" ).value = "Link"
Set colObject = Browser( "title:=Google").Page("title:=Google").ChildObjects( oDesc )
For x = 0 to colObject.Count - 1
'MsgBox colObject(x).GetROProperty("innertext")
colObject(x).Click
wait(2)
'点击第一个link时页面跳转到其它页面,需要返回当前首页
SystemUtil.Run "IEXPLORE.EXE","http://www.google.com.hk"
wait(2)
Next
上面已经获取到所有的link,但是实现click时就报错,请教大师们要如何实现? Dim oDesc,colObject
Set oDesc = Description.Create
oDesc( "micclass" ).value = "Link"
Set colObject = Browser( "title:=Google").Page("title:=Google").ChildObjects( oDesc )
Set ieBrowser = CreateObject("InternetExplorer.Application")
For x = 0 to colObject.Count - 1
'MsgBox colObject(x).GetROProperty("innertext")
colObject(x).Click
wait(2)
'SystemUtil.Run "IEXPLORE.EXE","http://www.google.com.hk"
ieBrowser.Navigate "http://www.google.com.hk"
wait(2)
Next
我用当前页面打开时,ieBrowser.Navigate "http://www.google.com.hk",这个不能执行 Dim oDesc,colObject
Set oAutoIt = CreateObject("AutoItX3.Control")
Set oDesc = Description.Create
oDesc( "micclass" ).value = "Link"
Set colObject=Browser("百度一下,你就知道").Page("百度一下,你就知道").ChildObjects(oDesc)
Browser("百度一下,你就知道").Page("百度一下,你就知道").Sync
Setting.WebPackage("ReplayType") = 2
For i = 0 to colObject.Count - 1
' MsgBox colObject(i).GetROProperty("innertext")
colObject(i).Click, ,micRightBtn
oAutoIt.Send("{DOWN 2}")
oAutoIt.Send("{ENTER}")
oAutoIt.Send ("^{tab}")
wait 3
oAutoIt.Send("^{w}")
next
Setting.WebPackage("ReplayType") = 1
可以通过模拟键盘操作完成这样的操作 Dim oDesc,colObject
SystemUtil.Run "IEXPLORE.EXE","http://www.google.com.hk"
Set oDesc = Description.Create
oDesc( "micclass" ).value = "Link"
Set ieBrowser=Browser( "Index:=0")
Set colObject = Browser( "title:=Google").Page("title:=Google").ChildObjects( oDesc )
For x = 0 to colObject.Count - 1
Set colObject = Browser( "title:=Google").Page("title:=Google").ChildObjects( oDesc )
'MsgBox colObject(x).GetROProperty("innertext")
colObject(x).Click
ieBrowser.Sync
wait(2)
ieBrowser.object.GoBack
Next
最主要的问题还是colObject被使用后就被释放了 必须重新取 回复 2# deadhunter
LZ要么用模拟键盘的操作来实现, 譬如点完第一个Link之后按Backspace回退键回到主页, 刚才试了下点击图片的link, 由于它的光标focus在搜索框里, 可以按TAB键来切换, 不然会影响Backspace键
Set wshShell=CreateObject("WScript.Shell")
wshShell.SendKeys "{TAB}"
wshShell.SendKeys "{Backspace}"
Set wshShell = nothing 谢谢大家,是colObject被使用后就被释放的原因
页:
[1]