Jump to content

its possible to select dropdown item with StringInStr ?


jmp
 Share

Go to solution Solved by AlessandroAvolio,

Recommended Posts

3 hours ago, AlessandroAvolio said:

Hello @jmp! Can you please post your code that show how you're selecting options in dropdown menu? Thank you

@AlessandroAvolio I am tried with this code

#include <IE.au3>
#include <MsgBoxConstants.au3>

$oIE = _IEAttach ("webpage")
Local $form0 = _IEGetObjById($oIE, "form2")
Local $oSelect = _IEFormElementGetObjByName($form2, "SchemeID")
$Division = _IEFormElementOptionSelect($oSelect, "3 : HIJ", 1, "byText")

 it was working but i want to select option by first 2 Character or number Like 3

HTML :

<select name="NameID" class="form-Control valid" id="ddlname" style="height: 32px;" data-val-required="" data-val="true" data-val-number="The field NameID must be a number."><option selected="selected" value="0">--Select--</option>
<option value="68">1 : ABC</option>
<option value="1">2 : EFG</option>
<option value="2">3 : HIJ</option>
<option value="3">10 : LMN</option>
<option value="4">6 : IPQ</option>
</select>

 

Link to comment
Share on other sites

  • Solution
4 hours ago, jmp said:

@Danp2 Then what is used for it ?

#include <IE.au3>

Main()

Func Main()

    Local Const $sSELECT_NAME = "choice"
    Local Const $sPARTIAL_STRING = "third"
    Local $oIE, $oSelect

    $oIE = _IECreate("https://yari-demos.prod.mdn.mozit.cloud/en-US/docs/Web/HTML/Element/select/_sample_.Basic_select.html")
    $oSelect = _IEGetObjByName($oIE, $sSELECT_NAME)

    For $oOption In $oSelect.options

        If StringInStr($oOption.text, $sPARTIAL_STRING) > 0 Then
            Return _IEFormElementOptionSelect($oSelect, $oOption.text, 1, "byText")
        EndIf
    Next

    Return 0

EndFunc

You need to get a list of all options of select and use Stringinstr with each of them. Use $oSelect.Option and then $oSelectOption.text like in the example upside. You also need to use a For...in..next loop in order to enumerate elements in an object collection.

https://www.autoitscript.com/autoit3/docs/keywords/ForInNext.htm

Edited by AlessandroAvolio
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...