Jump to content

Select random item in IE dropdown list


 Share

Recommended Posts

How can i select random item in IE dropdown list ?

Page Source

<div>
            <div><label id="blMember" class="control-label col-sm-push-4">select member :</label></div>
            <select class="form-Control" id="dlMember" name="dlMember" style="width: 190px;height:34px;"><option value="">-- Select Member --</option>
<option value="3100627027001">abc</option>
<option value="3100670827002">efg</option>
<option value="3010627082004">hij</option>
<option value="3100627827005">wxy</option>
<option value="3026270827006">mno</option>
</select>
        </div>

 

Link to comment
Share on other sites

24 minutes ago, Nine said:

Try reading all option tags value, put that in an array, use random to get a number, use array [number]

How to do it?

i am new on autoit, please give me little example 

Link to comment
Share on other sites

Link to comment
Share on other sites

@Nine, I am tried reading all option tags value using

$idlMember = _IEGetObjById($oIE, "dlMember")
$TXT = ""
$items = $idlMember.options
For $item in $items
    $TXT = $TXT & $item.value & @CRLF
Next
MsgBox(0, "", $TXT)

it was getting all option, How can i select randomly one option from these?

Edited by jmp
Link to comment
Share on other sites

On 7/20/2019 at 5:03 AM, jdelaney said:

get the count of options, _IEFormElementOptionSelect with mode = byIndex...use Random() to set the integer

Thanks @jdelaney, But It was select sometimes, Most of times it get error in line.

error.JPG.9749431efb54036b34b80fe20a56e14f.JPG

My code is

Local $oForm = _IEFormGetObjByName($oIE, "selectdldl")
Local $oSelect = _IEFormElementGetObjByName($oForm, "dlMember")
$iOptionCount = $oSelect.length
$nOption = Random(1, $iOptionCount)
_IEFormElementOptionSelect($oSelect, $nOption, 1, "byIndex")

 

Link to comment
Share on other sites

Possibly because you don't have the flag set on random to return an integer.   it's the third parameter.   Do a consoleoutput of $noption to debug.  otherwise you need to add debugging into the ie function to see what's going wrong

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

10 minutes ago, jdelaney said:

Possibly because you don't have the flag set on random to return an integer.   it's the third parameter.   Do a consoleoutput of $noption to debug.  otherwise you need to add debugging into the ie function to see what's going wrong

How can i do these? 

Link to comment
Share on other sites

9 hours ago, jdelaney said:

You still must update the second param to $ioptioncount-1

Like this? 

Local $oForm = _IEFormGetObjByName($oIE, "selectdldl") Local $oSelect = _IEFormElementGetObjByName($oForm, "dlMember") $iOptionCount = $oSelect.length $nOption = Random(1, $iOptionCount-1) _IEFormElementOptionSelect($oSelect, $nOption, 1, "byIndex")

Edited by jmp
Link to comment
Share on other sites

looks good.  Are you actually getting the count of the items from your $oSelect.length?  You might need to get the child nodes count.

ConsoleOutput($iOptionCount & @crlf) to check.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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...