WRed Posted August 24, 2013 Share Posted August 24, 2013 Hi, sorry for my english, I'll try to explain the problem. http://catalog.1001z.ru/bmw/#c3Q9PTQwfHxzdHM9PXsiMTAiOiJcdTA0MWNcdTA0MzBcdTA0NDBcdTA0M2FcdTA0MzAiLCIyMCI6IkJNVyIsIjMwIjoiMSBFODIiLCI0MCI6Ilx1MDQzYVx1MDQ0M1x1MDQzZlx1MDQzNSAxMThkIn18fGJtdD09Qk1XfHxicD09UHx8ZnY9PVZUfHxiYj09RTgyfHxtb2RlbD09MTE4ZHx8c21vZGVsPT1Db3V8fGVtb2RlbD090LrRg9C%2F0LV8fGljbz09MTY1NzI3 the link above, we can see selects without form http://d.pr/i/fYYS expandcollapse popup#include <IE1.au3> $oIE = _IEAttach("[CLASS:IEFrame]", 'Instance') Send("!{TAB}") $sSearch = "2008" Global $recordFinded = 0 $oDoc = _IEDocGetObj($oIE) $oArray = $oDoc.getElementsByTagName ("Select") For $element In $oArray Local $oItems = $element.options For $oItem In $oItems If String($oItem.text) = $sSearch Then ; try $element.click ;try $oItem.click _IEFormElementSetValue($element, $oItem.value) select but not fireevent $oItem.selected = TRUE ;try $element.fireEvent("onChange") ; try $element.fireEvent("OnClick") Endif Next Next ;or #cs ;Try this to $oOptions = _IETagNameGetCollection($oIE, "SELECT") If Not $recordFinded = 1 Then For $oOption In $oOptions _IEFormElementOptionSelect($oOption, $sSearch, 1, "byText", 1) Local $oItems = $oOption.options For $oItem In $oItems If String($oItem.text) = $sSearch Then _IEHeadInsertEventScript($oIE, $oOption, "onchange", "HM.set('c3Q9PTQwfHxzdHM9PXsiMTAiOiJcdTA0MWNcdTA0MzBcdTA0NDBcdTA0M2FcdTA0MzAiLCIyMCI6IkJNVyIsIjMwIjoiMSBFODIiLCI0MCI6Ilx1MDQzYVx1MDQ0M1x1MDQzZlx1MDQzNSAxMjBkIn18fGJtdD09Qk1XfHxicD09UHx8ZnY9PVZUfHxiYj09RTgyfHxtb2RlbD09MTIwZHx8c21vZGVsPT1Db3V8fGVtb2RlbD090LrRg9C%2F0LV8fGljbz09MTY1NzI3fHxmMDM9PTIwMDg%3D')") ; try _IEAction(_IEPropertyGet($oOption, "InnerText"), "click") ; try _IEAction(_IEPropertyGet($oItem, "InnerText"), "click") $oItem.selected = True ; try _IEAction($oItem, "click") $oOption.fireEvent("onChange") $oOption.fireEvent("OnClick") EndIf Next $recordFinded = 1 Next EndIf #ce ;i try anything :) But there is no fireEvent (maybe problem in version ie8?) onchange and onhashchange in history.js. When I choose manual option in last select - 2008, on page display a new select, but with script - nothing. Link to comment Share on other sites More sharing options...
dragan Posted August 24, 2013 Share Posted August 24, 2013 This works in IE9, I doubt it will work in IE8, but it's worth a shot: _IEFormElementSetValue($element, $oItem.value) Local $oEvt = $oIE.document.createEvent("HTMLEvents") $oEvt.initEvent("change", True, False) $element.dispatchEvent($oEvt) If it's not working for you, you might try this: _IEAction($element, 'focus');focusing helps sometimes with java functions _IEFormElementSetValue($element, $oItem.value) WRed 1 Link to comment Share on other sites More sharing options...
WRed Posted August 24, 2013 Author Share Posted August 24, 2013 (edited) This works in IE9, I doubt it will work in IE8, but it's worth a shot: _IEFormElementSetValue($element, $oItem.value) Local $oEvt = $oIE.document.createEvent("HTMLEvents") $oEvt.initEvent("change", True, False) $element.dispatchEvent($oEvt) If it's not working for you, you might try this: _IEAction($element, 'focus');focusing helps sometimes with java functions _IEFormElementSetValue($element, $oItem.value) $oIE = _IEAttach("[CLASS:IEFrame]", 'Instance') Send("!{TAB}") $sSearch = "2008" $recordFinded = 0 _IELinkClickByText ($oIE, $sSearch) If @error Then $oDoc = _IEDocGetObj($oIE) $oArray = $oDoc.getElementsByTagName ("Select") For $element In $oArray Local $oItems = $element.options For $oItem In $oItems If String($oItem.text) = $sSearch Then ConsoleWrite("Najdeno" & _IEPropertyGet($oItem, "InnerText")) _IEFormElementSetValue($element, $oItem.value) Local $oEvt = $oIE.document.createEvent("HTMLEvents") $oEvt.initEvent("change", True, False) $element.dispatchEvent($oEvt) Endif Next Next EndIf Error: Najdeno2008psfHomeSites1001x.rufile.au3 (177) : ==> The requested action with this object has failed.: Local $oEvt = $oIE.document.createEvent("HTMLEvents") Local $oEvt = $oIE.document.createEvent("HTMLEvents")^ ERROR what am I doing wrong ?) Edited August 24, 2013 by WRed Link to comment Share on other sites More sharing options...
dragan Posted August 24, 2013 Share Posted August 24, 2013 probably because IE8 doesn't support this function, but it was worth a shot. In this case, try the other thing I suggested: _IEAction($element, 'focus') _IEFormElementSetValue($element, $oItem.value) Link to comment Share on other sites More sharing options...
WRed Posted August 24, 2013 Author Share Posted August 24, 2013 probably because IE8 doesn't support this function, but it was worth a shot. In this case, try the other thing I suggested: _IEAction($element, 'focus') _IEFormElementSetValue($element, $oItem.value) I tried, but the result is the same. Option is selected, but without onchange event Link to comment Share on other sites More sharing options...
WRed Posted August 24, 2013 Author Share Posted August 24, 2013 Are your example work on ie 9, if yes maybe simple work on virtual machine with ie9 ?) Link to comment Share on other sites More sharing options...
dragan Posted August 24, 2013 Share Posted August 24, 2013 oke, instead of _IEFormElementSetValue, try using this function: _IEFormElementOptionSelect See in help files how to use it. Also don't forget to add _IEAction and "focus" before calling _IEFormElementOptionSelect Link to comment Share on other sites More sharing options...
WRed Posted August 24, 2013 Author Share Posted August 24, 2013 (edited) $oIE = _IEAttach("[CLASS:IEFrame]", 'Instance') Send("!{TAB}") $sSearch = "2008" $recordFinded = 0 _IELinkClickByText ($oIE, $sSearch) If @error Then $oDoc = _IEDocGetObj($oIE) $oArray = $oDoc.getElementsByTagName ("Select") For $element In $oArray Local $oItems = $element.options For $oItem In $oItems If String($oItem.text) = $sSearch Then ConsoleWrite("Najdeno" & _IEPropertyGet($oItem, "InnerText")) ;_IEFormElementSetValue($element, $oItem.value) _IEAction($element, 'focus') _IEFormElementOptionSelect($element, $sSearch, 1, "byText") Endif Next Next EndIf I apologize for the inconvenience, but steel don`t work select is chused, focused, but it`s done, without onchange Edited August 24, 2013 by WRed Link to comment Share on other sites More sharing options...
Solution dragan Posted August 24, 2013 Solution Share Posted August 24, 2013 Well, I like calling java functions directly, not activating their "onchange" or "onclick" function, IF I CAN. And you can do that on your page: #include <IE.au3> $the_URL = 'http://catalog.1001z.ru/bmw/#c3Q9PTQwfHxzdHM9PXsiMTAiOiJcdTA0MWNcdTA0MzBcdTA0NDBcdTA0M2FcdTA0MzAiLCIyMCI6IkJNVyIsIjMwIjoiMSBFODIiLCI0MCI6Ilx1MDQzYVx1MDQ0M1x1MDQzZlx1MDQzNSAxMThkIn18fGJtdD09Qk1XfHxicD09UHx8ZnY9PVZUfHxiYj09RTgyfHxtb2RlbD09MTE4ZHx8c21vZGVsPT1Db3V8fGVtb2RlbD090LrRg9C%2F0LV8fGljbz09MTY1NzI3' $oIE = _IECreate($the_URL) Sleep(2000);time given for JAVA to load some page elements, otherwise, you will get NO "select" elements _ChangeSelect('01', 2);select 2nd element in 1st "select" control Sleep(1000);time given for java to react and execute the function _ChangeSelect('02', 1);select 1st element in 2nd "select" control Sleep(1000);time given for java to react and execute the function _ChangeSelect('03', 1);select 1st element in 3rd "select" control Sleep(1000);time given for java to react and execute the function _ChangeSelect('04', 3);select 3rd element in 4th "select" control Sleep(1000);time given for java to react and execute the function Func _ChangeSelect($SelName, $OptIndex) Local $oSelects = _IETagNameGetCollection($oIE, 'select') For $oSelect in $oSelects If $oSelect.name == $SelName Then Local $oOptions = $oSelect.options Local $Counter = -1 For $oOption in $oOptions $Counter += 1 If $Counter = $OptIndex Then $oIE.document.parentWindow.execScript('HM.set("' & $oOption.value & '");') Return EndIf Next Return EndIf Next EndFunc MsgBox(0, 'DONE!', 'Press OK to close the script') _IEQuit($oIE) Because JAVA is changing htmlsource of the $oIE, then you must call _IETagNameGetCollection($oIE, 'select') after each changed element, like it's shown in the script above. WRed 1 Link to comment Share on other sites More sharing options...
WRed Posted August 24, 2013 Author Share Posted August 24, 2013 Awesome! Thank you very much! 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