Jump to content
Sign in to follow this  
Seminko

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

Recommended Posts

Seminko

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

Share this post


Link to post
Share on other sites
SmOke_N

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
  • Like 1

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.

Share this post


Link to post
Share on other sites
Seminko
8 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

Obliged! Thank you!

Share this post


Link to post
Share on other sites
Seminko
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

Share this post


Link to post
Share on other sites
Seminko

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

 

Share this post


Link to post
Share on other sites
SmOke_N

:thumbsup:


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.

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  

  • Similar Content

    • XinYoung
      By XinYoung
      For fun, I'm building an app that opens a webpage and refreshes it every 30 seconds.
      But once the script performs _IEAction($oIE, "refresh"), the GUI closes.
      Any help is appreciated.
       

      #include <ButtonConstants.au3>
      #include <EditConstants.au3>
      #include <GUIConstantsEx.au3>
      #include <StaticConstants.au3>
      #include <WindowsConstants.au3>
      #include <WinAPIFiles.au3>
      #include <Array.au3>
      #include <File.au3>
      #include <Excel.au3>
      #include <DateTimeConstants.au3>
      #include <MsgBoxConstants.au3>
      #include <WinAPIShellEx.au3>
      #include <MsgBoxConstants.au3>
      #include <Date.au3>
      #include <ComboConstants.au3>
      #include <guimenu.au3>
      #include <IE.au3>
      HotKeySet("{F4}", "_Exit")
      ;Open the file(s) in the selected folder
      $extension = ".txt"
      $app2openWith = @SystemDir & "\notepad.exe"
      Func Begin()
          Global $loopTrick = 0
          #Region ### START Koda GUI section ### Form=c:\users\mchu\downloads\autoit\my code\form1.kxf
          Global $UI = GUICreate("Hit Em Up!", 256, 113, -1, -1)
          GUISetBkColor(0x000000)
          $menu = _GUICtrlMenu_GetSystemMenu($UI)
          _GUICtrlMenu_EnableMenuItem($menu, $SC_CLOSE, 1, False)
          Global $url = GUICtrlCreateInput("https://www.youtube.com/watch?v=dQw4w9WgXcQ", 81, 8, 160, 21)
          $Label1 = GUICtrlCreateLabel("Target:", 16, 8, 55, 17)
          GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
          GUICtrlSetColor(-1, 0x00FF00)
          Global $StartBut = GUICtrlCreateButton("Start", 16, 40, 67, 25)
          GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
          GUICtrlSetBkColor(-1, 0x008000)
          $Label2 = GUICtrlCreateLabel("(Press F4 to Exit)", 96, 40, 8000, 17)
          GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
          GUICtrlSetColor(-1, 0x00FF00)
          GUISetState(@SW_SHOW)
          #EndRegion ### END Koda GUI section ###
          While 1
              $UIfunc = GUIGetMsg()
              Select
                  Case $UIfunc = $GUI_EVENT_CLOSE
                      _Exit()
                  Case $UIfunc = $StartBut
                      If GUICtrlRead($url) = "" Then
                          MsgBox(48, "Um...", "Give me a target you idiot.")
                      Else
                          GUICtrlSetState($url, $GUI_DISABLE)
                          GUICtrlSetState($StartBut, $GUI_DISABLE)
                          Start()
                      EndIf
              EndSelect
          WEnd
      EndFunc   ;==>Begin
      Func Start()
          If $loopTrick = 0 Then
              Global $oIE = _IECreate(GUICtrlRead($url))
              _IELoadWait($oIE)
              Again()
          ElseIf $loopTrick = 1 Then
              Sleep(3000)
              _IEAction($oIE, "refresh")
              Sleep(3000)
              Start()
          EndIf
      EndFunc   ;==>Start
      Func Again()
          $loopTrick = 1
          Start()
      EndFunc   ;==>Again
      Func _Exit()
          Exit
      EndFunc   ;==>_Exit
    • mLipok
      By mLipok
      I have some problems with windows explorers.
      Here is my testing snippet:
      ;~ #RequireAdmin _Example() MsgBox(1, '', '@error = ' & @error & @CRLF & '@extended = ' & @extended) Func _Example() Local $oShell = ObjCreate("shell.application") If @error then Return SetError(1, @extended, 0) Local $oShellWindows = $oShell.windows If @error then Return SetError(2, @extended, 0) If $oShellWindows = Null Then Return SetError(3, 0, 0) Local $iCount = $oShellWindows.Count If @error then Return SetError(4, $iCount, 0) Return SetExtended($iCount,1) EndFunc ;==>_Example Normally this should return in extended number of opened InternetExplorer + WindowsExplorer.
      But in some cases I encounter a problem with this, as there happens situation when @extended returns 0 even if I had already opened IE.
      Here is one of them:
      I have some script which is working fine with IE on about 100 computers.
      In this specyfic case this script starts his work, and after few minutes he stoped works.
      All the time IE is still responsive, I can click on elements and go to specyfic places.
      Restoring the script did not help because _IEAttach () does not work.
      All you need to do is restart InternetExplorer.
       
      As a result of all my investigation I had done you can see this script snippet above.
      In my case My primary script was doing their job, but when he stops, IE was still responsive but this above snippet starts to return @error=0 and @extended = 0 when @extended should be at least =1 (this opened Internet Explorer instance)
      QUESTION:
      Has anyone already encountered such a problem?
      Does anyone know any solution or has an idea for further diagnostics?
       
      btw.
      I have one solution which would fix it - I mean Windows reinstall, but this is not good solution, as I always like to know the esense of the problem.
       
      EDIT:
      I know you can say show the script........ this is not possible you have no access to this site, and about 100 computers works well, so this i not related to my script.
      The more so that the problem is not related to my main scripts, and the problem is simply how IE behaves - which is illustrated by the above piece of code.
       
    • Nareshm
      By Nareshm
      i want to repeat this function 
      _IELoadWait($oIE, "url 2") $checkb = _IEGetObjById($oIE,"checkb") _IEAction($checkb,"click") $img = _IEGetObjById($oIE,"img") _IEAction($img,"click") _IELoadWait($oIE, "url 1") $btnfy = _IEGetObjById($oIE,"btnvfy") _IEAction($btnfy,"click") until my targeted webpage not found.
    • Robdog1955
      By Robdog1955
      I'm trying to click a button on a web page. I have added a couple of MsgBox lines to allow me to watch what happens on the page. As you can see the first half of my script enters data into text boxes on the page. I have no problem there. I just cannot click on the region buttons. The "set focus" line causes an outline to appear around the EU button and the "click button" line causes the "Pick a Region" text to disappear. Here is the code I have so far.
      #include <IE.au3> Local $oIE = _IECreate("http://questchecker.com/") Local $iQuestID = "123456" Local $sCharacterName = "CharacterName" Local $colForms = _IEFormGetCollection($oIE) $iCount = 0 For $oForm In $colForms $oFormElements = _IEFormElementGetCollection($oForm) For $oFormElement In $oFormElements $iCount = $iCount + 1 Local $sTagName = StringLower($oFormElement.tagName) Local $sElementType = $oFormElement.type Local $sElementName = $oFormElement.name Switch $iCount Case 6 _IEFormElementSetValue($oFormElement, "MyRealm", 0) ; realm Case 7 _IEFormElementSetValue($oFormElement, $sCharacterName, 0) Case 8 _IEFormElementSetValue($oFormElement, $iQuestID, 0) EndSwitch Next Next Local $oButtons = _IEGetObjByName($oIE, "questForm") For $oButton In $oButtons If _IEFormElementGetValue($oButton) = "US" Then MsgBox(0, "", "Click Okay to set focus") _IEAction($oButton, "focus") MsgBox(0, "", "Click Okay to click button") _IEAction($oButton, "click") ExitLoop EndIf Next MsgBox(0, "", "Click Okay to quit") _IEQuit($oIE) Exit  
    • Dent
      By Dent
      As the title says. I open IE11 and navigate to a page with the following HTML5 file upload container in Capture0.JPG
      I want to click Add Files but I haven't been able to. Here's the code that handles the Add Files button in Capture.JPG
      _IEGetObjectById and then using _IEAction to click it doesn't work. I can't give access to the actual page unfortunately because it's password protected.
      All suggestions welcome.


×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.