Jump to content
Sign in to follow this  
jmp

Select random item in IE dropdown list

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>

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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 

Share this post


Link to post
Share on other sites

Look in help file, for the following statements :

_IETagNameGetCollection ()

Random ()

_ArrayDisplay ()

Each statement is fully described with excellent examples...

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites
1 hour ago, Nine said:

Really ? New ? BS ! You are on your own...

It was a basic script

Share this post


Link to post
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

Share this post


Link to post
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")

 

Share this post


Link to post
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.

Share this post


Link to post
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? 

Share this post


Link to post
Share on other sites
9 minutes ago, jdelaney said:

Oh, byindex is 0 based.   set random to 0, count-1

@jdelaney

I want to skip first option from selection.

Share this post


Link to post
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

Share this post


Link to post
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.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...