Jump to content

Advanced IE.au3 use


lionfaggot
 Share

Recommended Posts

Alright so this has probably been done already but i've been learning just how much you can do with IE

specifically i have found that _IETagNameGetAllCollection is powerful as holy heck

for instance, and this may help at least a few folks. say a form of tagname input has an outerhtml wildcard of forks

to click on this element is simple, requiring very little to make it work. here is an example:

the object elements outerhtml will look like this in this example:

<input id="forks" class="forks">

here is what i would do to click on this form, lets also assume that this event loads a new page, i initially didnt know how to wait for this due to _IELoadWait() being unable to follow a form action, that function only works with navigations. and so the solution is to find string wildcards or differences in the next page that only happen on that page after you click said element. you just have it wait until that wildcard appears in the outerhtml property of the browser object. and without further speaking i will demonstrate the method:

#include <IE.au3>

Local $oIE = _IECreate('http://examplecrap.com')
Local $oElements = _IETagNameAllGetCollection($oIE)
For $oElement In $oElements
if StringInStr($oElement.outerhtml, "forks") And $oElement.tagname = "input" Then
_IEAction($oElement, "click")
_CWait()
EndIf
Next
func _CWait()
Do
sleep(100)
Until StringInStr(_IEPropertyGet($oIE, "outerhtml"), "wildcardheretostopwait")
EndFunc

this above script can be used almost anywhere in any context. ive found that this is by far the easiest most universal way to use ie to select and fill out objects based on properties.

Link to comment
Share on other sites

#include <IE.au3>
;########################### EXAMPLE ################################
;#                                                                  #
;#$object = _IECreate("http://www.google.com/")                     #
;#                                                                  #
;#_IESelectWCard($object, 'maps', 'span', 'click')                  #
;#                                                                  #
;#Local $strw = "Google Maps"                                       #
;#                                                                  #
;#_IEWildWait($strw, 5)                                             #
;#                                                                  #
;########################## /Example ################################

Global $object

Func _IESelectWCard($object, $objWildProperty, $objTagname, $objAction = "", $objText = "")
    Local $oElements = _IETagNameAllGetCollection($object)
    For $oElement In $oElements
        Local $tagname = $oElement.tagname
        Local $str = $oElement.outerhtml
        If StringInStr($str, $objWildProperty) And $tagname = $objTagname Then
            If $objText <> "" Then
                Return _IEFormElementSetValue($oElement, $objText)
            Else
                If $objAction = "" Then
                    Return $oElement
                Else
                    Return _IEAction($oElement, $objAction)
                EndIf
            EndIf
            ExitLoop
        EndIf
    Next
    Return 0
EndFunc   ;==>_IESelectWCard

Func _IEWildWait($strw, $timeout = "")
    If $timeout <> "" Then
        Local $x = 1
    EndIf
    Do
        If $timeout <> "" Then
            Sleep(1000)
            If $x = $timeout Then
                Return 0
                ExitLoop
            EndIf
            $x += 1
        Else
            Sleep(100)
        EndIf
    Until StringInStr(_IEPropertyGet($object, "outerhtml"), $strw)
    Return 1
EndFunc   ;==>_IEWildWait

Select an element by outerhtml wildcard and perform an action or text action with the specified form element then wait for the next page to load a wildcard in $object.outerhtml with only 2 functions

the above code puts the entire process into two functions. _IESelectWCard($object, 'maps', 'span', 'click') will click on the maps link on google. also you can specify $objText as anything other than null to fill in forms that require text input. if you specify no text or action the function will simply return the element object. then there is _IEWildWait($strw, 5) will specify that the script should pause until the next page has loaded with a resulting wildcard of $strw in the source code. you can also specify a timeout just in case it fails or goes too slow. i chose 5, it will wait 1 second 5 times before the loop exits. this is just in case the load event hangs or fails for whatever reason. enjoy!

yes i realize _IELinkClickByText would also work in the example. thats not the point, the point is that this will work when most everything else fails. it almost ALWAYS works for near everything

Edited by lionfaggot
Link to comment
Share on other sites

#include <_IEWild.au3>
$object = _IECreate("http://www.omegle.com/")
_IESelectWCard($object, "newtopicinput", "input", "", "Mustard")
_IESelectWCard($object, "textbtn", "img", "click")
_IEWildWait("You're now chatting with a random stranger. Say hi!", 5)

more examples, this will enter "Mustard" into the omegle interest section then click on the text chat button and wait until a chat has started.

Link to comment
Share on other sites

  • 4 weeks later...

one more thing, i suppose i should showcase one final example. instead of performing an action on the element as click or text input. if you specify no action the object element is returned. then you can perform any action on it, such as the following:

$objReturn = _IESelectWCard($object, 'textInput', 'input')
_IEAction($objReturn, 'focus')
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...