ihousden Posted March 18, 2011 Share Posted March 18, 2011 Another noob question re IE.au3 Im having limited success in scraping data from a report page. Some fields work fine, others dont. The ones im having a problem with are the dropdown boxes. Im not interested selecting any text from these boxes, just determing what is curerntly selected. Here is my code so far: ; Includes: #include <IE.au3> #include <Array.au3> DIM $resname DIM $smode DIM $desc DIM $sdate DIM $edate $oIE = _IECreate("http://you_cant_get_here_without_authentication") _IELoadWait ($oIE) Sleep(300) $oForm = _IEFormGetObjByName ($oIE, "frmDtl") $resname = _IEFormElementGetObjByName ($oForm, "Desc") $smode = _IEGetObjByName ($oForm, "schedColor") $desc = _IEFormElementGetObjByName ($oForm, "ExtDesc") $sdate = _IEFormElementGetObjByName ($oForm, "schedDate") $edate = _IEFormElementGetObjByName ($oForm, "schedEndDate") MsgBox(0, "Form Element Value", _IEFormElementGetValue ($resname)) MsgBox(0, "Form Element Value", _IEFormElementGetValue ($smode)) MsgBox(0, "Form Element Value", _IEFormElementGetValue ($desc)) MsgBox(0, "Form Element Value", _IEFormElementGetValue ($sdate)) MsgBox(0, "Form Element Value", _IEFormElementGetValue ($edate)) $smode is throwing error 7. I have tried _IEFormElementGetObjByName and _IEGetObjByName with no success. See the atached image. This is IE developter tools with the field in question highlighted. The table is within the same form as the other elements (not enough real estate to show entire tree). Im admittedly not that familiar yet with the IE.au3 syntax yet. I know when the answer comes it will be a DOH!! moment. Cheers Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 19, 2011 Share Posted March 19, 2011 The parent Select object won't tell you what's selected. You have to walk through the child Option objects and check each one to see if it's .selected property is true. For some types of selections, there might be more than one. #include <IE.au3> $oIE = _IE_Example("Form") MsgBox(32, "Continue", "Change selection, then click OK to continue...") $oSelect = _IEGetObjByName($oIE, "selectExample") $colChildren = _IETagNameGetCollection($oSelect, "Option") For $oChild In $colChildren $sValue = $oChild.value $sText = $oChild.innerText $vSelected = $oChild.selected ConsoleWrite("Debug: Value = " & $sValue & "; Text = " & $sText & "; Selected = " & $vSelected & @LF) Next Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Tvern Posted March 20, 2011 Share Posted March 20, 2011 Try this: While 1 $smode = _IEGetObjByName ($oForm, "schedColor") If IsObj($oTable) Then ExitLoop Sleep(100) WEnd You should add a timeout mechanism if it works. I had to use this yesterday when a <Select> control would only load shortly after the page reported it was ready. Might be the same for you. Link to comment Share on other sites More sharing options...
ihousden Posted March 28, 2011 Author Share Posted March 28, 2011 Thanks guys. I was off last week. Ill give that a try today and report results. Cheers. Link to comment Share on other sites More sharing options...
ihousden Posted March 28, 2011 Author Share Posted March 28, 2011 Tvern. Tried yours first because it was simpler but got an error of an undeclared variable with "oTable". not sure if I was missing an include or what... PsaltyDS. Thanks for your code. worked great. [Console output] Debug: Value = 2; Text = VC Special Support; Selected = False Debug: Value = 3; Text = No Support; Selected = False Debug: Value = 4; Text = VC Connect Only; Selected = False Debug: Value = 6; Text = External Support; Selected = False Debug: Value = 7; Text = VC Self Support; Selected = True Debug: Value = 8; Text = AV Self Support; Selected = False Debug: Value = 0; Text = AV Support; Selected = False Debug: Value = 9; Text = VC Full Support; Selected = False I had to add the if statement to insert the innertext of the selected option to my $smode variable. $oSelect = _IEGetObjByName($oIE, "schedColor") $colChildren = _IETagNameGetCollection($oSelect, "Option") For $oChild In $colChildren $sValue = $oChild.value $sText = $oChild.innerText $vSelected = $oChild.selected if $oChild.selected = "True" Then $smode = $oChild.innerText EndIf ConsoleWrite("Debug: Value = " & $sValue & "; Text = " & $sText & "; Selected = " & $vSelected & @LF) Next I realize that this will only work if one option is selected, which is the case for my use. finally, I changed: MsgBox(0, "Form Element Value", _IEFormElementGetValue ($smode)) to MsgBox(0, "Form Element Value", $smode) to properly report the scraped info back to me. Now to build a function out of this... Thanks much guys. Link to comment Share on other sites More sharing options...
ihousden Posted March 28, 2011 Author Share Posted March 28, 2011 For posterity, im posting the function. I hope someone will find it useful. I know the code could be tighter but hey, im a noob, quit complaining. expandcollapse popup#include <IE.au3> #include <Array.au3> DIM $resname DIM $smode DIM $desc DIM $sdate DIM $edate DIM $DDLName DIM $DDLSelect $oIE = _IECreate("http://you_cant_get_here_from_there") _IELoadWait ($oIE) Sleep(300) $oForm = _IEFormGetObjByName ($oIE, "frmDtl") $resname = _IEFormElementGetObjByName ($oForm, "Desc") ; Query Drop Down List $DDLName = "schedColor" ; name of DDL DDLQuery() $smode = $DDLSelect ; currently selected innertext of DDL ; End Query Drop Down List $desc = _IEFormElementGetObjByName ($oForm, "ExtDesc") $sdate = _IEFormElementGetObjByName ($oForm, "schedDate") $edate = _IEFormElementGetObjByName ($oForm, "schedEndDate") MsgBox(0, "Form Element Value", _IEFormElementGetValue ($resname)) MsgBox(0, "Form Element Value", $smode) MsgBox(0, "Form Element Value", _IEFormElementGetValue ($desc)) MsgBox(0, "Form Element Value", _IEFormElementGetValue ($sdate)) MsgBox(0, "Form Element Value", _IEFormElementGetValue ($edate)) Func DDLQuery() $oSelect = _IEGetObjByName($oIE, $DDLName) $colChildren = _IETagNameGetCollection($oSelect, "Option") For $oChild In $colChildren $sValue = $oChild.value $sText = $oChild.innerText $vSelected = $oChild.selected if $oChild.selected = "True" Then $DDLSelect = $oChild.innerText EndIf ConsoleWrite("Debug: Value = " & $sValue & "; Text = " & $sText & "; Selected = " & $vSelected & @LF) Next EndFunc Thanks again for the help PsaltyDS The_Key_Maker 1 Link to comment Share on other sites More sharing options...
Tvern Posted March 29, 2011 Share Posted March 29, 2011 Tvern. Tried yours first because it was simpler but got an error of an undeclared variable with "oTable". not sure if I was missing an include or what...I just copied that snippet from my script and renamed $oTable from my script to $smode from your script in the post. I forgot to rename the second $oTable though.Glad you got it working. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now