Afaan Posted December 14, 2016 Share Posted December 14, 2016 Is there any way to select an option from a <select> which is itself updated by a previous <select> by AJAX? Link to comment Share on other sites More sharing options...
Danp2 Posted December 14, 2016 Share Posted December 14, 2016 I would imagine so. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Afaan Posted December 14, 2016 Author Share Posted December 14, 2016 Just now, Danp2 said: I would imagine so. And that way is? Link to comment Share on other sites More sharing options...
Danp2 Posted December 14, 2016 Share Posted December 14, 2016 Using _IEFormElementOptionSelect I would imagine. <shrug> You asked a question and I answered it. If you want assistance with a specific website, then you will need to provide more information, such as: The site name / URL Your code showing what you have tried thus far If the site isn't open to the public, then it would be good if you found an example of one that is so that we can use it to test and provide you with a working solution. mLipok 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Afaan Posted December 14, 2016 Author Share Posted December 14, 2016 _IEFormElementOptionSelect works fine with regular <select>s. I use it to set the first select which triggers an ajax request which in turn gets the options for the second select. If I call _IEFormElementOptionSelect on that, it just does nothing. Is there any way that I can wait for the second select to load the options first before attempting to select one? My code so far: Func WaitForSelect($argForm, $argSelect, $argOptVal) While 1 $options = _IETagNameAllGetCollection(_IEFormElementGetObjByName($argForm, $argSelect)) For $opt In $options Sleep(100) If $opt.value = $argOptVal Then _IEFormElementOptionSelect(_IEFormElementGetObjByName($argForm, $argSelect), $argOptVal) If _IEFormElementGetObjByName($argForm, $argSelect).value = $argOptVal Then ExitLoop 2 EndIf EndIf Next WEnd EndFunc It works sometimes, sometimes it doesn't. I need something reliable. Thanks! Link to comment Share on other sites More sharing options...
Danp2 Posted December 14, 2016 Share Posted December 14, 2016 You are making multiple calls to _IEFormElementGetObjByName. Is there a reason that you can't call it once and then use the object reference for subsequent calls, ie: $oSelect = _IEFormElementGetObjByName($argForm, $argSelect) $options = _IETagNameAllGetCollection($oSelect) Also, please provide a better description than "doesn't work". What happens? Does it loop forever in the function? Or what? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Afaan Posted December 14, 2016 Author Share Posted December 14, 2016 Yeah, I could do that. And by "doesn't work", I meant that it fails to select the option and just moves on to the next field. Link to comment Share on other sites More sharing options...
Danp2 Posted December 14, 2016 Share Posted December 14, 2016 I wonder if something like this would work better? Func WaitForSelect($argForm, $argSelect, $argOptVal, $argDelay = 500) Local $oSelect, $oOptions, $nCnt1, $nCnt2 $oSelect = _IEFormElementGetObjByName($argForm, $argSelect) While 1 $oOptions = _IETagNameAllGetCollection($oSelect) $nCnt1 = @extended Sleep($argDelay) $oOptions = _IETagNameAllGetCollection($oSelect) $nCnt2 = @extended If $nCnt1 = $nCnt2 Then _IEFormElementOptionSelect($oSelect, $argOptVal) ExitLoop EndIf WEnd EndFunc  Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Afaan Posted December 15, 2016 Author Share Posted December 15, 2016 I found a work-around which seems to work fine. Func SetAjaxSelect($argForm, $argSelect, $argOptVal) $theSelect = _IEFormElementGetObjByName($argForm, $argSelect) $options = 0 Do $options = _IETagNameAllGetCollection($theSelect) Sleep(50) Until IsObj($options) For $opt in $options If $opt.value = $argOptVal Then Sleep(200) _IEFormElementOptionSelect($theSelect, $argOptVal) Return EndIf Next EndFunc  Link to comment Share on other sites More sharing options...
Danp2 Posted December 15, 2016 Share Posted December 15, 2016 Glad you found a working solution. Can you explain why you need the For loop? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Afaan Posted December 16, 2016 Author Share Posted December 16, 2016 Since the select is being dynamically updated, I need to make sure that the option I am selecting does indeed exist in the option list. That's why I need the For loop. Link to comment Share on other sites More sharing options...
Danp2 Posted December 16, 2016 Share Posted December 16, 2016 How do you detect that the option didn't exist in the calling script? FWIW, I would have tried removing the loop, calling _IEFormElementOptionSelect, and then checking to see if the call succeeded / failed. Latest Webdriver UDF Release Webdriver Wiki FAQs 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