Sign in to follow this  
Followers 0
drego

Problem working with result of _IELinkGetCollection

6 posts in this topic

I'm trying to loop through a bunch of links and perform some operations. Here is my code:

$oLinks = _IELinkGetCollection($ie1)
$iNumLinks = @extended
For $oLink In $oLinks
If StringInStr($oLink.href,"offerdetails") > 0 Then
  _IENavigate($ie1,$oLink.href)
  $html = _IEBodyReadHTML($ie1)
  $offerName = _StringBetween($html,'DrkBlue">','</')
  ;MsgBox(0,"offer name",$offerName)
EndIf
Next

The If statement is evaluating true and it is visiting the first link. However, as soon as it visits the first link my program dies with the error:

The requested action with this object has failed.:

If StringInStr($oLink.href,"offerdetails") > 0 Then

If StringInStr($oLink.href^ ERROR

Share this post


Link to post
Share on other sites



cant sleep until i solve this

Share this post


Link to post
Share on other sites

As soon as you use _IENavigate, the current document and all of it's objects are destroyed (including $oLinks), so when it tries to loop again, neither $oLinks nor $oLink is valid any longer.

Perhaps you want to open a second browser and send your navigation to that browser so that your original context is preserved or perhaps you want to store all of the hrefs in an array and then loop through it... depends on what you are trying to accomplish.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

As soon as you use _IENavigate, the current document and all of it's objects are destroyed (including $oLinks), so when it tries to loop again, neither $oLinks nor $oLink is valid any longer.

Perhaps you want to open a second browser and send your navigation to that browser so that your original context is preserved or perhaps you want to store all of the hrefs in an array and then loop through it... depends on what you are trying to accomplish.

Dale

I think I would like to store them all in an array

Share this post


Link to post
Share on other sites

im having trouble creating the array. how should I do it?

Share this post


Link to post
Share on other sites

this is all wrong

$oLinks = _IELinkGetCollection($ie1)
$iNumLinks = @extended
Local $linkAr[$iNumLinks]
$place = 0
For $oLink In $oLinks
If StringInStr($oLink.href,"offerdetails") > 0 Then
  ;_IENavigate($ie1,$oLink.href)
  ;_ArrayAdd($linkAr,$oLink.href)
  $linkAr[$place] = $oLink.href
  $place = $place + 1
  ;$html = _IEBodyReadHTML($ie1)
  ;$offerName = _StringBetween($html,'DrkBlue">','</')
  ;MsgBox(0,"offer name",$offerName)
  MsgBox(0,"",$linkAr[4])
EndIf
Next

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0