Jump to content
Sign in to follow this  

Help with IE.au3 and manipulating a web page

Recommended Posts



I have spent most of the day writing this script then trimming the working version

Here is what I am trying to do

  • Search Microsoft Update Catalog web page for a particular KB number
  • Check that results are returned
  • Search through the results to find the correct link based on a few search strings
  • Get information about the update such as title, classification modified etc
  • Click the correct link
  • Get the url of the page that is opened (for future use)

The script does all the above but one part, the _IEAction($oLink, 'click') bit, it does not work as I would like when using IE8. If I manually click the link it opens in a popup window if I use the _IEAction a box pops up saying I have a popup blocker installed and to turn it off and does not navigate to the link. I could turn the blocker off but want it to work without that.

I can get the correct url to open the popup window but it means using hard coded links and I was hoping to automate the process by clicking so as to future proof it (as much as possible) if the page layout changes

Here is what I need help with

  • Someone to check through the code and to see if it can be trimmed further or a better method to achieve my goals
  • Help with getting the url for the _IENavigate function so that it is built from the html of the web page instead of a literal string


#include <ie.au3>
#include <array.au3>

; open IE and navigate to Update catalog homepage
Local $oIE = _IE_OpenWebPage('http://catalog.update.microsoft.com')

; search for kb number and open the page and check for returned results
_IE_SearchForKBNumber($oIE, 'KB2667402')

; get the table with the specified name
$oID = _IEGetObjById($oIE, 'ctl00_catalogBody_updateMatches')

; write the table info to an array
Local $aTableData = _IETableWriteToArray($oID)
Local $sArch = 'x64', $sWinVer = 'Windows 7', $sTitle = ''

; loop through the array
For $i = 1 To UBound($aTableData) - 1
    $sTitle = $aTableData[1][$i]
    ; check for search string matches
    If StringInStr($sTitle, $sArch) And StringInStr($sTitle, $sWinVer) Then ExitLoop

; get all the links on the page
Local $oLinks = _IELinkGetCollection($oIE), $sUpdateID = ''

For $oLink In $oLinks
    If StringInStr(_IEPropertyGet($oLink, "innerText"), $sTitle) then
        ; this causes pop up blocker warning
;~       _IEAction($oLink, 'click')
;~       If @error then MsgBox(0,'', @error)

        ; i have to now get link ID and hard code link later
        $sUpdateID = StringReplace($oLink.id, '_link', '')

    ; navigate to hard coded link (bolloxed if link changes) need a better way to get the link
_IENavigate($oIE, 'http://catalog.update.microsoft.com/v7/site/ScopedViewInline.aspx?updateid=' & $sUpdateID)

Func _IE_CheckForSearchResults($oBrowser, $sKBNumber)
    Local $sFunc = '_IEDocReadHTML'
    Local $shtml = _IEDocReadHTML($oBrowser)

    If Not @error Then
        ; split the html page to an array for searching
        Local $aHTML = StringSplit($shtml, @LF)

        ; search for errors with kb number
        $sFunc = '_ArraySearch'
        Local $iIndex = _ArraySearch($aHTML, 'We did not find any results for', 0, 0, 0, 1)

        If @error = 6 Then Return

        If $iIndex > 0 Then Return SetError(1, 0, 'We did not find any results for ' & $sKBNumber)

    Return SetError(1, 0, '_CheckForSearchResults,' & $sFunc & ',' & @error & ',' & @extended)
EndFunc   ;==>_IE_CheckForSearchResults

Func _IE_OpenWebPage($sUrl)
    Local $oBrowser = _IECreate($sUrl, 0, 1)
    If Not @error Then Return $oBrowser

    ; handle error
    Return SetError(1, 0, '_IE_OpenMUCHomePage,_IECreate,' & @error & ',' & @extended)
EndFunc   ;==>_IE_OpenMUCHomePage

Func _IE_SearchForKBNumber($oBrowser, $sKBNumber)
;~  _logAdd('Searching for ' & $sKBNumber & '...¦')
    _IE_SubmitSearchRequest($oBrowser, $sKBNumber)
    If @error Then Return SetError(1)

    ; check search returned some results
    _IE_CheckForSearchResults($oBrowser, $sKBNumber)
    If @error Then Return SetError(1)
EndFunc   ;==>_IE_SearchForKBNumber

Func _IE_SubmitSearchRequest($oBrowser, $sKBNumber)
    Local $sFunc = '_IEGetObjByName'

    ; reference the mainFormHome form
    Local $sFunc = '_IEFormGetObjByName'
    Local $oForms = _IEFormGetObjByName($oBrowser, 'mainFormHome')

    If Not @error Then
        ; reference the search box
        $sFunc = '_IEFormElementGetObjByName'
        Local $oSearchBox = _IEFormElementGetObjByName($oForms, 'searchTextBox')

        If Not @error Then
            ; set the kb number as the text
            $sFunc = '_IEFormElementsetValue'
            _IEFormElementSetValue($oSearchBox, $sKBNumber)

            If Not @error Then
                ; get the search button link
                $sFunc = '_IEGetObjById'
                Local $oSearchLink = _IEGetObjById($oBrowser, 'searchButtonLink')

                If Not @error Then
                    ; click on the link

                    $sFunc = '_IEGetObjById'
                    _IEAction($oSearchLink, 'click')

                    If Not @error Then
                        ; wait for page to load
                        $sFunc = '_IELoadWait'

                        If Not @error Then Return

    Return SetError(1, 0, '_SubmitSearchRequest,' & $sFunc & ',' & @error & ',' & @extended)
EndFunc   ;==>_IE_SubmitSearchRequest

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