Jump to content

Getting the contents of dropdown list in IE

Recommended Posts


I'm trying to get the content of dropdown list. Using the example script in _IEFormElementOptionSelect

; Open a browser with the form example, get reference to form, get reference
; to select element, cycle 10 times selecting options byValue, byText and byIndex

#include <IE.au3>

Local $oIE = _IE_Example("form")
Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm")
Local $oSelect = _IEFormElementGetObjByName($oForm, "selectExample")
_IEAction($oSelect, "focus")
For $i = 1 To 0 ;changed here to 0 from 10, no need to select items
    _IEFormElementOptionSelect($oSelect, "Freepage", 1, "byText")
    _IEFormElementOptionSelect($oSelect, "midipage.html", 1, "byValue")
    _IEFormElementOptionSelect($oSelect, 0, 1, "byIndex")

;I have added the following to see the content of the dropdown
$x = _IEPropertyGet($oSelect, "innerText")
ConsoleWrite("Content is: " & $x & @CRLF)


My output is like that:

Content is: Homepage Midipage Freepage


It's sure okay, but I have two questions:

  1. The variable that is returned with x is a whole string? "Homepage Midipage Freepage "
  2. There are three options to select. I can split based on space. But if the text itself includes a space, how can I split these options?


Link to post
Share on other sites

If data is all you need, i would do this way (but there is other methods):

#include <Array.au3>
#include <IE.au3>

Local $oIE = _IE_Example("form")

Local $sHTML = _IEDocReadHTML($oIE)
If Not @error Then
    $sHTML = StringRegExp($sHTML, '(?s)<select name="selectExample">(.*?)</select>', 1) ;assuming that the list may change over time grabbing all the inside the tags
    If IsArray($sHTML) Then
        $sHTML = StringRegExp($sHTML[0], '(?s)>(.*?)<', 3)
        If IsArray($sHTML) Then _ArrayDisplay($sHTML)



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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...