taylansan Posted April 6, 2016 Share Posted April 6, 2016 Hello, I'm trying to get the content of dropdown list. Using the example script in _IEFormElementOptionSelect ; Open a browser with the form example, get reference to form, get reference ; to select element, cycle 10 times selecting options byValue, byText and byIndex #include <IE.au3> Local $oIE = _IE_Example("form") Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm") Local $oSelect = _IEFormElementGetObjByName($oForm, "selectExample") _IEAction($oSelect, "focus") For $i = 1 To 0 ;changed here to 0 from 10, no need to select items _IEFormElementOptionSelect($oSelect, "Freepage", 1, "byText") Sleep(1000) _IEFormElementOptionSelect($oSelect, "midipage.html", 1, "byValue") Sleep(1000) _IEFormElementOptionSelect($oSelect, 0, 1, "byIndex") Sleep(1000) Next ;I have added the following to see the content of the dropdown $x = _IEPropertyGet($oSelect, "innerText") ConsoleWrite("Content is: " & $x & @CRLF) _IEQuit($oIE) My output is like that: Content is: Homepage Midipage Freepage It's sure okay, but I have two questions: The variable that is returned with x is a whole string? "Homepage Midipage Freepage " There are three options to select. I can split based on space. But if the text itself includes a space, how can I split these options? TY. Link to comment Share on other sites More sharing options...
Juvigy Posted April 6, 2016 Share Posted April 6, 2016 You don't need _IEFormElementOptionSelect( You can remove the whole loop. You can get the 'innerhtml' and then use a simple RegEx to retrieve all the options. SO , something like : $x = _IEPropertyGet($oSelect, "innerText") $options = StringRegEx($x , pattern) The pattern would depend on the html code of the page. Link to comment Share on other sites More sharing options...
MichaelHB Posted April 6, 2016 Share Posted April 6, 2016 If data is all you need, i would do this way (but there is other methods): #include <Array.au3> #include <IE.au3> Local $oIE = _IE_Example("form") Sleep(5000) Local $sHTML = _IEDocReadHTML($oIE) If Not @error Then $sHTML = StringRegExp($sHTML, '(?s)<select name="selectExample">(.*?)</select>', 1) ;assuming that the list may change over time grabbing all the inside the tags If IsArray($sHTML) Then _ArrayDisplay($sHTML) $sHTML = StringRegExp($sHTML[0], '(?s)>(.*?)<', 3) If IsArray($sHTML) Then _ArrayDisplay($sHTML) EndIf EndIf Exit 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