Jump to content

[SOLVED] IE How to grab all OPTION values out of a select class


Seminko
 Share

Recommended Posts

I am now able to populate the dropdown menus at https://www.tipcars.com/.

The dropdowns are dynamic and do not have a Text value, only ids.

Is there a way to get all the available options from a dropdown?

$url = "https://www.tipcars.com/"
$oIE = _IECreate($url)
_IELoadWait($oIE)

$oDownloadSamples = _IEGetObjById($oIE, "homepage_vyhl_frm_vozidlo")
_IEFormElementOptionSelect($oDownloadSamples, "C")

Above code, populates ID 'C' into the 'druh' dropdown, which results in selecting 'užitkové'. 

Is there a way so I can grab all of the options from the dropdown menu? I could easily grab all the IDs but I am afraid they will change in the future so I would much rather match the text titles and assign the option IDs grabbed from site.

This is what the options are according to Chrome:

<select class="w1"id="homepage_vyhl_frm_vozidlo"name="homepage_vyhl_frm_vozidlo"onchange="try{NABIDKA_VOZIDEL_FORMULAR.naplnSelectZnacka('homepage_vyhl_frm');GLOBAL.pocetInzerceHZ('homepage_vyhl_frm','vozidlo');}catch(ex){odeslatJsChybu('formHOMEPAGE onChange 1: ' + ex.message, 'formHomePage onChange 1', -1);}">
<option value="A" style="color: black;">osobní a terénní (56 334)</option>
<option value="C" style="color: black;">užitkové (4 333)</option>
<option value="D" style="color: black;">nákladní (3 742)</option>
<option value="E" style="color: black;">autobusy (56)</option>
<option value="F" style="color: black;">obytné (373)</option>
<option value="G" style="color: black;">přívěsy (1 179)</option>
<option value="J" style="color: black;">motorky (780)</option>
<option value="S" style="color: black;">pracovní stroje (605)</option>
<option value="L" style="color: black;">ostatní (235)</option></select>

Also, this cannot be grabbed by _INetGetSource.

Thanks

Edited by Seminko
typos
Link to comment
Share on other sites

  • Moderators

Object from id: object = homepage_vyhl_frm_vozidlo

Get object array of items: items = object.options

For in loop: item in items

Text of each object/select item:  item.text

Untested pseudo code:

#include <IE.au3>

Global $goMainIE = _IECreate("url here"); can use _IEAttach or _IECreate here
If @error Then Exit 10011
Global $goID = _IEGetObjById($goMainIE, "homepage_vyhl_frm_vozidlo")
If Not IsObj($goID) Then Exit 10012
Global $goItems = $goID.options
If Not IsObj($goItems) Then Exit 10013
Global $gsItemList = ""
For $oItem In $goItems
    $gsItemList &= $oItem.text & @CRLF
Next
MsgBox(64, "Items List", $gsItemList)

 

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

43 minutes ago, SmOke_N said:

Object from id: object = homepage_vyhl_frm_vozidlo

Get object array of items: items = object.options

For in loop: item in items

Text of each object/select item:  item.text

Untested pseudo code:

I kinda jumped the gun on this one. Still not solved.

The text is being grabbed correctly but the thing I'm missing are the option values.

<option value="A" style="color: black;">osobní a terénní (56 334)</option>
- osobní a terénní (56 334) - this is being grabbed
- "A" - this is what I need also

I tried google but I don't even know what these '.parameter' things are called at least I wasn't able to find any reference to object.options.

Edited by Seminko
Link to comment
Share on other sites

Aaaaand I figured it out. You just go item.value instead of item.text.

$url = "https://www.tipcars.com/"

$oIE = _IECreate($url)
_IELoadWait($oIE)

$oDownloadSamples = _IEGetObjById($oIE, "homepage_vyhl_frm_vozidlo")

$TXT = ""
$items = $oDownloadSamples.options
For $item in $items
    $TXT = $TXT & $item.value & @CRLF
Next

 

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

×
×
  • Create New...