Search code examples
htmlformsinternet-explorerautomationautoit

How to target form elements other than by id, class or screen location?


I am trying to fill out a form using Internet Explorer. The webpage contains no id's nor class names. So currently I move the mouse to a relative position based on the size of the screen. But this screen resolution dependency is undesired.

Given the webpage's (internal website) lack of classes/ids, how to target its HTML form inputs, text areas, combo boxes, drop downs, date pickers, and buttons other than by screen location?


Solution

  • You could iterate all input elements to identify the ones you need :

    #include <IE.au3>
    $oIE = _IECreate("http://www.google.com")
    $oAs = _IETagnameGetCollection($oIE, "input")
    $i = 1
    For $oA In $oAs
       _IEPropertySet($oA, "innertext", $i)
       $i = $i + 1
    Next  
    

    Next you could use the $i variable to set the right values. In this example the Google search field is the fourth input element so you could fill it out this way:

    #include <IE.au3>
    $oIE = _IECreate("http://www.google.com")
    $oAs = _IETagnameGetCollection($oIE, "input")
    $i = 1
    For $oA In $oAs
       If $i = 4 Then _IEPropertySet($oA, "innertext", "MyValue")
       $i = $i + 1
    Next