Sign in to follow this  
Followers 0
uteotw

How to get the text in Form Element Options?

5 posts in this topic

When a Form Element type is of "select-one" (Drop Down) how can I grab the text that is actually displayed by each option?

I can get how many option items there are.

I can get the value of each option.

But I don't understand how the get the text associated with each.

Here is the code I've written so far.

$oIE = _IE_Example ("form")

;Detect each Forms
$oForms = _IEFormGetCollection ($oIE)
ConsoleWrite("Forms Info - There are " & @extended & " forms on this page" & @CRLF & @CRLF)


For $oForm In $oForms
    ConsoleWrite("Form Name = " & $oForm.name & @CRLF & @CRLF)

    ;Detect each Forms Elements (drop downs)
    $oForm = _IEFormGetObjByName($oIE, $oForm.name)
    $oFormElements = _IEFormElementGetCollection ($oForm, -1)
        
    For $oFormElement In $oFormElements
        ConsoleWrite("Form Name / Element = " & $oFormElement.name & " - " & $oFormElement.type & @CRLF)
        
        If $oFormElement.type = "select-one" Then
            $oElementOptions = _IEFormElementGetObjByName($oForm, $oFormElement.name)
            
            ConsoleWrite("Form Name / Element / Options # = " & $oElementOptions.options.length & " items" & @CRLF)
            
            For $i = 0 to $oElementOptions.options.length-1
                _IEFormElementOptionselect ($oElementOptions, $i, 1, "byIndex")
                _IEFormElementGetValue ($oElementOptions)
                ConsoleWrite(_IEFormElementGetValue ($oElementOptions))
                ConsoleWrite(@CRLF)
            Next
            
        EndIf
        
        ConsoleWrite(@CRLF)
    Next
    
    ConsoleWrite(@CRLF & @CRLF)
Next

Any suggestions?

Thanks

uteotw

Share this post


Link to post
Share on other sites



Something like this?

#include <IE.au3>

$oIE = _IE_Example("form")

;Detect each Forms
$oForms = _IEFormGetCollection($oIE)
ConsoleWrite("Forms Info - There are " & @extended & " forms on this page" & @CRLF & @CRLF)


For $oForm In $oForms
    ConsoleWrite("Form Name = " & $oForm.name & @CRLF & @CRLF)
    
    ;Detect each Forms Elements (drop downs)
    $oForm = _IEFormGetObjByName($oIE, $oForm.name)
    $oFormElements = _IEFormElementGetCollection($oForm)
    
    For $oFormElement In $oFormElements
        ConsoleWrite("Form Name / Element = " & $oFormElement.name & " - " & $oFormElement.type & @CRLF)
        
        If $oFormElement.type = "select-one" Then
            $oItems = $oFormElement.options
            For $oItem In $oItems
                ConsoleWrite("Form Name / Element / Options = " & $oItem.text & @CRLF)
            Next
        EndIf
        ConsoleWrite(@CRLF)
    Next
    ConsoleWrite(@CRLF & @CRLF)
Next

Share this post


Link to post
Share on other sites

Super Duper. Exactly what I wanted.

I think I tried something like options.text in some place but couldn't get it to work.

Thanks a lot big_daddy

Share this post


Link to post
Share on other sites

Super Duper. Exactly what I wanted.

I think I tried something like options.text in some place but couldn't get it to work.

Thanks a lot big_daddy

No problem, glad I could help!

Share this post


Link to post
Share on other sites

Here is what I got now...

Basically, it's just mimicing what IE_Builder does, but in the Console prompt, to help me work on pages with Form.

#include <IE.au3>

$oIE = _IE_Example("form")

;Detects each Forms
$oForms = _IEFormGetCollection($oIE)
ConsoleWrite("Forms Info - There are " & @extended & " forms on this page" & @CRLF & @CRLF)

;Loops through each Form
For $oForm In $oForms
    ConsoleWrite("FormName = " & $oForm.name & @CRLF & @CRLF)
    
    ;Detect each Forms Elements
    $oForm = _IEFormGetObjByName($oIE, $oForm.name)
    $oFormElements = _IEFormElementGetCollection($oForm)
    
    ;Loops through each Form Elements
    For $oFormElement In $oFormElements
        ConsoleWrite("FormName/Element Type >> Name >> Value = " & $oFormElement.type & " >> " & $oFormElement.name & " >> " & _IEFormElementGetValue($oFormElement) & @CRLF)
        
        ;If Form Element is a Drop Down or List
        If $oFormElement.type = "select-one" OR $oFormElement.type = "select-multiple" Then
            
            ;Detects Form Element Options
            $oFormElementItems = $oFormElement.options
            ConsoleWrite("FormName/Element/Options Total = " & $oFormElementItems.options.length & " items" & @CRLF)        
            
            For $oFormElementItem In $oFormElementItems
                ConsoleWrite("Form Name/Element/Options Index >> Value >> Text  = " & $oFormElementItem.index & " >> " & $oFormElementItem.value & " >> " & $oFormElementItem.text & @CRLF)
            Next
        Else
            ;Nothing
        EndIf
        ConsoleWrite(@CRLF)
    Next
    ConsoleWrite(@CRLF & @CRLF)
Next

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