dragan Posted July 17, 2013 Share Posted July 17, 2013 Hi all, I'm trying to expand the sub-option in the IE. On this page:http://www.tripadvisor.com/Hotels-g187791-Rome_Lazio-Hotels.html there is a "span"-button called "More" How can I expand Hotel class, Amenities, or Hotel brand? I've tried this: expandcollapse popup#include <IE.au3> Global $oIE _Main() Func _Main() ConsoleWrite('................................................................................' & @CRLF) _StartIE() ;Start Internet Explorer _LoadWebPage() ;Load webpage in the Internet Explorer _expandControl() ;expand the hotel class If IsObj($oIE) Then _IEQuit($oIE) ConsoleWrite('................................................................................' & @CRLF) EndFunc Func _StartIE() ConsoleWrite('> Info - Starting IE... please wait...' & @CRLF) $oIE = _IECreate() If @error Then ConsoleWrite('! Error - Starting IE failed... script will now be terminated...' & @CRLF) Exit EndIf ConsoleWrite('> Info - IE started successfully.' & @CRLF) EndFunc Func _LoadWebPage() Local $pageLoaded = False Do If NOT IsObj($oIE) Then ConsoleWrite('! Error - IE is no longer a valid object, script will now be terminated...' & @CRLF) MsgBox(BitOR(48, 262144), 'Error', 'IE is no longer a valid object.' & @CRLF & _ @CRLF & _ 'Script will be terminated...') Exit EndIf Local $the_url = 'http://www.tripadvisor.com/Hotels-g187791-Rome_Lazio-Hotels.html' ConsoleWrite('- Loading - Please wait, IE is navigating to: ' & $the_url & @CRLF) _IENavigate($oIE, $the_url) If @error Then ConsoleWrite('! Error - Page could not be loaded: ' & $the_url & @CRLF) If MsgBox(BitOR(3, 48, 262144), 'Error', 'Page: ' & @CRLF & _ $the_url & @CRLF & _ 'couldn''t be loaded.' & @CRLF & _ @CRLF & _ 'Would you like to try again?') = 7 Then Exit EndIf Else $pageLoaded = True EndIf Until $pageLoaded = True ConsoleWrite('+ Info - Page loaded successfully: ' & $the_url & @CRLF) EndFunc Func _expandControl() If NOT IsObj($oIE) Then ConsoleWrite('! Error - IE is no longer a valid object, script will now be terminated...' & @CRLF) MsgBox(BitOR(48, 262144), 'Error', 'IE is no longer a valid object.' & @CRLF & _ @CRLF & _ 'Script will be terminated...') Exit EndIf Local $allSpans = _IETagNameGetCollection($oIE, 'span') For $oneSpan in $allSpans If StringInStr($oneSpan.classname, 'hotel_filter more sprite-date_picker-triangle no_cpu') Then _IEAction($oneSpan, 'focus') _IEAction($oneSpan, 'click') Sleep(1000) ConsoleWrite('> Info - "MORE" span is opened' & @CRLF) MsgBox(BitOR(64, 262144), 'test', 'Just opened "MORE"') Local $allULs = _IETagNameGetCollection($oIE, 'ul') For $oneUL in $allULs If $oneUL.classname == 'expandFilterItems more' Then Local $allDivs = _IETagNameGetCollection($oneUL, 'div') For $oneDiv in $allDivs If $oneDiv.classname == 'nameItem sprite-filter-expand' Then ;Hotel class _IEAction($oneDiv, 'focus') _IEAction($oneDiv, 'click') ConsoleWrite('- Question - is "Hotel class" expanded??' & @CRLF) MsgBox(BitOR(64, 262144), 'test', 'Is "Hotel class" expanded?') ExitLoop 3 EndIf Next ExitLoop 2 EndIf Next ExitLoop EndIf Next EndFunc Link to comment Share on other sites More sharing options...
dragan Posted July 18, 2013 Author Share Posted July 18, 2013 24-hour bump... Link to comment Share on other sites More sharing options...
dragan Posted July 22, 2013 Author Share Posted July 22, 2013 last bump... Link to comment Share on other sites More sharing options...
Bert Posted July 22, 2013 Share Posted July 22, 2013 (edited) Is the code on the website written in Javascript? Edited July 22, 2013 by YogiBear The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Bert Posted July 22, 2013 Share Posted July 22, 2013 I looked in http://userscripts.org for any scripts one could use with greasmonkey. You may be able to make a greasemonkey script to do what you need. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
dragan Posted July 22, 2013 Author Share Posted July 22, 2013 the "Inspect element" is giving me this: <ul class="expandFilterItems more"> <li class="hotel_class expandFilterItem"> <div class="nameItem sprite-filter-expand"> Hotel class </div> <div class="toggleItem"> </div> </li> <li class="amenities expandFilterItem"> <div class="nameItem sprite-filter-expand"> Amenities </div> <div class="toggleItem"> </div> </li> <li class="hotel_brand expandFilterItem"> <div class="nameItem sprite-filter-expand"> Hotel brand </div> <div class="toggleItem"> </div> </li> </ul> I have also found this element, and I think these two must be connected somehow: expandcollapse popup<fieldset class="filtersLHN hotCls js_disableEmpty"> <p id="zfc_toggle" onclick="ta.servlet.HACSearch.toggleFilterExpansion(event, this)" class="filterHeading sprite-arrow_toggle_blu_dwn hvrIE6"> Hotel class </p> <div class="chkSet imgLblChkSet" id="zfc_default"> <input type="checkbox" id="zfc_0" name="zfc_0" value="0" checked="checked" class=" input_filter default " onclick="ta.call('ta.servlet.HACSearch.handleCheckSetOnClick', event)"> <label for="zfc_0" id="zfc_0_lbl" class=""> All <span id="zfc_0_count" style="display: inline;"> (1262) </span> </label> </div> <div class="chkSet imgLblChkSet"> <input type="checkbox" id="zfc_5" name="zfc_5" value="5" class=" input_filter " onclick="ta.call('ta.servlet.HACSearch.handleCheckSetOnClick', event)"> <label for="zfc_5" id="zfc_5_lbl" class=""> <span class="rate rate_cl cl50"> <img id="zfc_5_img_lbl" class="sprite-ratings-ltgrn" src="http://c1.tacdn.com/img2/x.gif"> </span> <span class=" ratecnt_cl " id="zfc_5_count" style="display: inline;"> (32) </span> </label> </div> <div class="chkSet imgLblChkSet"> <input type="checkbox" id="zfc_4" name="zfc_4" value="4" class=" input_filter " onclick="ta.call('ta.servlet.HACSearch.handleCheckSetOnClick', event)"> <label for="zfc_4" id="zfc_4_lbl" class=""> <span class="rate rate_cl cl40"> <img id="zfc_4_img_lbl" class="sprite-ratings-ltgrn" src="http://c1.tacdn.com/img2/x.gif"> </span> <span class=" ratecnt_cl " id="zfc_4_count" style="display: inline;"> (278) </span> </label> </div> <div class="chkSet imgLblChkSet"> <input type="checkbox" id="zfc_3" name="zfc_3" value="3" class=" input_filter " onclick="ta.call('ta.servlet.HACSearch.handleCheckSetOnClick', event)"> <label for="zfc_3" id="zfc_3_lbl" class=""> <span class="rate rate_cl cl30"> <img id="zfc_3_img_lbl" class="sprite-ratings-ltgrn" src="http://c1.tacdn.com/img2/x.gif"> </span> <span class=" ratecnt_cl " id="zfc_3_count" style="display: inline;"> (302) </span> </label> </div> <div class="chkSet imgLblChkSet"> <input type="checkbox" id="zfc_2" name="zfc_2" value="2" class=" input_filter " onclick="ta.call('ta.servlet.HACSearch.handleCheckSetOnClick', event)"> <label for="zfc_2" id="zfc_2_lbl" class=""> <span class="rate rate_cl cl20"> <img id="zfc_2_img_lbl" class="sprite-ratings-ltgrn" src="http://c1.tacdn.com/img2/x.gif"> </span> <span class=" ratecnt_cl " id="zfc_2_count" style="display: inline;"> (123) </span> </label> </div> <div class="chkSet imgLblChkSet"> <input type="checkbox" id="zfc_1" name="zfc_1" value="1" class=" input_filter " onclick="ta.call('ta.servlet.HACSearch.handleCheckSetOnClick', event)"> <label for="zfc_1" id="zfc_1_lbl" class=""> <span class="rate rate_cl cl10"> <img id="zfc_1_img_lbl" class="sprite-ratings-ltgrn" src="http://c1.tacdn.com/img2/x.gif"> </span> <span class=" ratecnt_cl " id="zfc_1_count" style="display: inline;"> (25) </span> </label> </div> </fieldset> I have tried to simulate both, clicking onto the first element, and simulating (calling "onclick" function from the 2nd element), and neither was expanding the "Hotel class"... Thanks for suggestion on the greasmonkey, but shouldn't this function do the same as greasemonkey would:? Local $allPs = _IETagNameGetCollection($oIE, 'p') For $oneP in $allPs If $oneP.id == 'zfa_toggle' Then ConsoleWrite($oneP.classname & @CRLF);just to see that I have the right element Local $oEvt = $oIE.document.createEvent("HTMLEvents") $oEvt.initEvent("click", True, False) $oneP.dispatchEvent($oEvt) ExitLoop EndIf Next p.s. this last function works only on IE9+, and it's calling "onclick" function from selected element/object. Link to comment Share on other sites More sharing options...
Bert Posted July 22, 2013 Share Posted July 22, 2013 I remember reading somewhere the IE functions had a spot of bother with the newer version of IE. I'm not the best at the IE controls but I would assume making the greasemonkey script display the options you want as a default would be a much better solution for you. In this manner you would not have to click on anything. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
dragan Posted July 23, 2013 Author Share Posted July 23, 2013 I tried in newer and older IE, it makes no difference. Also, I'm kinda forced not to use any other additional plugin, only my script, so I can't really experiment with greasemonkey scripts, but tnx for suggestion. Anyway, I did make it work, but with controlclick. I don't like controlclick because it will open adds and popups because it simulates real mouse click: expandcollapse popup#include <IE.au3> Global $oIE _Main() Func _Main() ConsoleWrite('................................................................................' & @CRLF) _StartIE() ;Start Internet Explorer _LoadWebPage() ;Load webpage in the Internet Explorer _expandControl() ;expand the hotel class ConsoleWrite('................................................................................' & @CRLF) MsgBox(BitOR(64, 262144), 'Info', 'Press OK to close the script') If IsObj($oIE) Then _IEQuit($oIE) EndFunc Func _StartIE() ConsoleWrite('> Info - Starting IE... please wait...' & @CRLF) $oIE = _IECreate() ;~ $oIE = _IECreate('about:blank', -1, 0) If @error Then ConsoleWrite('! Error - Starting IE failed... script will now be terminated...' & @CRLF) Exit EndIf ConsoleWrite('> Info - IE started successfully.' & @CRLF) EndFunc Func _LoadWebPage() Local $pageLoaded = False Do If NOT IsObj($oIE) Then ConsoleWrite('! Error - IE is no longer a valid object, script will now be terminated...' & @CRLF) MsgBox(BitOR(48, 262144), 'Error', 'IE is no longer a valid object.' & @CRLF & _ @CRLF & _ 'Script will be terminated...') Exit EndIf Local $the_url = 'http://www.tripadvisor.com/Hotels-g187791-Rome_Lazio-Hotels.html' ConsoleWrite('- Loading - Please wait, IE is navigating to: ' & $the_url & @CRLF) _IENavigate($oIE, $the_url) If @error Then ConsoleWrite('! Error - Page could not be loaded: ' & $the_url & @CRLF) If MsgBox(BitOR(3, 48, 262144), 'Error', 'Page: ' & @CRLF & _ $the_url & @CRLF & _ 'couldn''t be loaded.' & @CRLF & _ @CRLF & _ 'Would you like to try again?') = 7 Then Exit EndIf Else $pageLoaded = True EndIf Until $pageLoaded = True ConsoleWrite('+ Info - Page loaded successfully: ' & $the_url & @CRLF) EndFunc Func _expandControl() If NOT IsObj($oIE) Then ConsoleWrite('! Error - IE is no longer a valid object, script will now be terminated...' & @CRLF) MsgBox(BitOR(48, 262144), 'Error', 'IE is no longer a valid object.' & @CRLF & _ @CRLF & _ 'Script will be terminated...') Exit EndIf Local $oIEhwnd = _IEPropertyGet($oIE, "hwnd") If @error Then ConsoleWrite('! Error - there is no IE window...') MsgBox(BitOR(48, 262144), 'Error', 'IE window does not exist.') _IEQuit($oIE) Exit EndIf Local $allSpans = _IETagNameGetCollection($oIE, 'span') For $oneSpan in $allSpans If StringInStr($oneSpan.classname, 'hotel_filter more sprite-date_picker-triangle no_cpu') Then _IEAction($oneSpan, 'focus') _IEAction($oneSpan, 'click') Sleep(1000) ConsoleWrite('> Info - "MORE" span is opened' & @CRLF) Local $allULs = _IETagNameGetCollection($oIE, 'ul') For $oneUL in $allULs If $oneUL.classname == 'expandFilterItems more' Then Local $allDivs = _IETagNameGetCollection($oneUL, 'div') For $oneDiv in $allDivs If $oneDiv.classname == 'nameItem sprite-filter-expand' Then ;Hotel class BlockInput(1) _ActivateAndResizeWin($oIEhwnd) Sleep(250) ConsoleWrite($oneDiv.innertext & @CRLF) Local $iBrowserX = _IEPropertyGet($oneDiv, "browserx") Local $iBrowserY = _IEPropertyGet($oneDiv, "browsery") Local $iWidth = _IEPropertyGet($oneDiv, "width") Local $iHeight = _IEPropertyGet($oneDiv, "height") ControlClick($oIEhwnd, "", "", "left", 1, $iBrowserX + $iWidth/2, $iBrowserY + $iHeight/2) BlockInput(0) Sleep(250) WinSetState($oIEhwnd, '', @SW_SHOW) ConsoleWrite('- Question - is "Hotel class" expanded??' & @CRLF) MsgBox(BitOR(64, 262144), 'Question', 'Is "Hotel class" expanded?') ExitLoop 3 EndIf Next ExitLoop 2 EndIf Next ExitLoop EndIf Next EndFunc Func _ActivateAndResizeWin($hwnd) If NOT IsHWnd($hwnd) then Return SetError(1) WinActivate($hwnd) WinWaitActive($hwnd) Local $winsize = WinGetPos($hwnd) If @error then Return SetError(2) Local $shouldResize = False $newWidth = $winsize[2] $newHeight = $winsize[3] If $newWidth < 960 Then $shouldResize = True $newWidth = 960 EndIf If $newHeight < 768 Then $shouldResize = True $newHeight = 768 EndIf If $shouldResize = True Then ConsoleWrite('> Info - resizing IE window...') WinMove($hwnd, '', $winsize[0], $winsize[1], $newWidth, $newHeight) EndIf EndFunc Is there more elegant solution? Without using controlclick? 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