Sign in to follow this  
Followers 0
mdcastle

Loop help

4 posts in this topic

I want to get all the links on a webpage and search until I find a string - when the string is found I want to click the link. If the string isn't found on that page I want to click an image to go to the next page and do the search again. I've got so far but i'm struggling with the syntax. Any help would be greatly appreciated.

The code below works well as long as the string is on the first page!

$sMyString = String($ReadCell)
  $oLinks = _IELinkGetCollection($OpenIE)
  For $oLink in $oLinks
   $sLinkText = _IEPropertyGet($oLink, "innertext")
   If StringInStr($sLinkText, $sMyString) Then
    _IEAction($oLink, "click")
    ExitLoop
   Else
    ContinueLoop
   EndIf
  Next

I click the image to go to the next page with this:

_IEImgClick($OpenIE, "next", "alt")

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Well if the code is working up until the point you navigate to the next page then the problem is likely connected to that. It could just be that you need to reorganize your code. Perhaps put the page navigation inside the loop, or call a function to run the loop each time you load a new page. It's hard to figure it out from what you have posted.

Edited by czardas

Share this post


Link to post
Share on other sites

Thanks czardas for the heads up.. I solved it with this.

Do
  $oLinks = _IELinkGetCollection($OpenIE)
  For $oLink in $oLinks
   $sLinkText = _IEPropertyGet($oLink, "innertext")
   If StringInStr($sLinkText, $sMyString) Then
    _IEAction($oLink, "click")
    ExitLoop 2
   Else
    ContinueLoop
   EndIf
  Next
  _IEImgClick($OpenIE, "next", "alt")
  Until WinExists("Supplier Setup Confirmation - Windows Internet Explorer") = 1

Share this post


Link to post
Share on other sites

I haven't tested your code, but it looks like you got it nailed. ;)

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