I’m working on a scraper just to take data out of 3 select boxes in a third-party website running on ASP.NET, but the problem here is that they are cascading (not sure if this is how it’s called). So what appears in the second select input depends on what’s selected in the first one, and I want to get all the possibilities so I can store them.
My problem:
I’m having a hard time figuring how to trigger the change (or whatever) event so it updates the second input. How can I do it?
I’m using casperjs to do this btw, but it doesn’t matter, I just need a way to do it programmatically from the frontend javascript.
So, if it works in the chrome console it will work for me.
The form is in this page http://www.tuti.pt/contrat/net/default.aspx and the inputs I’m talking about are the ‘Distrito’ and ‘Concelho’.
Sorry for the long read but I think I couldn’t hide more details.
What I’ve tried?
The usual thing, I really thought .click() would work but not, it didn’t so it should be some asp.net special event.
Then I’ve placed a break and it seems this particular peace of stack seems interesting to find what I need.
Sys.Extended.UI.CascadingDropDownBehavior._clearItems (default.aspx:13)
Sys.Extended.UI.CascadingDropDownBehavior._setOptions (default.aspx:13)
Sys.Extended.UI.CascadingDropDownBehavior._onParentChange (default.aspx:13)
w.createDelegate (ScriptResource.axd:2)
w.addHandler.b.query.each.g (ScriptResource.axd:2)
If someone has knowledge on this I would appreciate to have some help on it.
I just saw there seems to be a method that could be what I’m looking for: raiseSelectionChanged(eventArgs). I just don’t know in what object should I call it and what args should I pass :s
This last info took from http://www.asp.net/ajaxlibrary/act_CascadingDropdown.ashx
So, still not found how to trigger the event, actually now I doubt it’s even possible… Maybe if there is a way to get the object Sys.Extended.UI.CascadingDropDownBehavior responsible for that select input, but I have no idea how to do that.
My solution for now is to use the Web Service used by that ‘library?’ to update the inputs. I found the url for it inspecting he object in Chrome console. Just created a break point for when the second input is changed and when changing the first select it stops there. Then I inspected the CascadingDropDownBehavior object that was in the locals, and found the web service url in _serviceMethod 😀
Update:
Ok, so at the end I just programmed a lil ruby script to fetch from the API/WS wich was pretty simple and easy, since there seems be no way to trigger the events from the javascript browser runtime.