Sign in to follow this  
Followers 0
sigil

having trouble setting values in Mapquest

9 posts in this topic

#1 ·  Posted (edited)

I'm trying to use IE.au3 to let a user submit a complete itinerary to Mapquest, because Mapquest only lets you enter one destination at a time. But I can't set the value for adding another destination. Here's the code:

#include <ie.au3>

$mqobj=_iecreate("www.mapquest.com")

;get all the elements you need for the initial route
$routeform=_ieformgetcollection($mqobj,2)
$startcityel=_ieformelementgetobjbyname($routeform,"1c")
$startstateel=_ieformelementgetobjbyname($routeform,"1s")
$endcityel=_ieformelementgetobjbyname($routeform,"2c")
$endstateel=_ieformelementgetobjbyname($routeform,"2s")

;set and submit the initial route
_ieformelementsetvalue($startcityel,"Los Angeles")
_ieformelementsetvalue($startstateel,"CA")
_ieformelementsetvalue($endcityel,"San Diego")
_ieformelementsetvalue($endstateel,"CA")
_ieformsubmit($routeform)


;get the elements for adding next destination
$maps=_ieformgetobjbyname($mqobj,"maps-form")
$address=_ieformelementgetcollection($maps,1)

;set and submit the next destination
_ieformelementsetvalue($address,"Las Vegas, NV")
msgbox(0,"",_ieformelementgetvalue($address))        ;test to make sure value has changed
_ieformsubmit($maps)

Everything works fine until

_ieformelementsetvalue($address,"Las Vegas, NV")
msgbox(0,"",_ieformelementgetvalue($address))
_ieformsubmit($maps)

at which point I get sent to the generic Mapquest search page, which is not what I want--I want to add the new destination to the total itinerary. Note that this line

_ieformelementsetvalue($address,"Las Vegas, NV")

doesn't fill in that form element on the page, although checking the value with

_ieformelementgetvalue($address,"Las Vegas, NV")

shows that the city name seems to have been entered.

I've also tried

$button=_ieformelementgetcollection($maps,2)
_ieaction($address,"click")
send("Las Vegas, NV")
_ieaction($button,"click")

which doesn't work either.

Edited by sigil

Share this post


Link to post
Share on other sites



It looks to me that the second yfor m you want is loc2-form instead of maps-form.

Are you using DebugBar?

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

It looks to me that the second yfor m you want is loc2-form instead of maps-form.

Are you using DebugBar?

Dale

I searched the source code for the Driving Directions page (the one that I reach once I submit the initial start/end points), and didn't find "loc2-form" or "loc-form". I did find "dir-form", which looks almost identical to "maps-form", but that gave the same results when I substituted it.

I'll check out DebugBar and see what I find.

Share this post


Link to post
Share on other sites

OK, I used DebugBar. I'm pretty sure I identified the field that I'm trying to fill as the 2nd element in the 5th form. So I used:

$maps=_ieformgetcollection($mqobj,4)                  ;gets the 5th form
$address=_ieformelementgetcollection($maps,1)             ;gets that form's 2nd element
_ieformelementsetvalue($address,"Las Vegas, NV")          ;sets new value for element
msgbox(0,"",_ieformelementgetvalue($address))             ;displays new value
_ieformsubmit($maps)                                                    ;submits form with new value

But that just takes me back to http://www.mapquest.com/search?

Share this post


Link to post
Share on other sites

Take a look at the remarks for _IEFormSubmit... there is Javascript on the Go button that does more than a Submit.

;get the elements for adding next destination
$maps=_ieformgetobjbyname($mqobj,"loc2-form")
$address=_ieformelementgetcollection($maps,1)

;set and submit the next destination
_ieformelementsetvalue($address,"Las Vegas, NV")
msgbox(0,"",_ieformelementgetvalue($address))         ;test to make sure value has changed
$oButton = _IEGetObjById($mqobj, "loc2-button")
_IEAction($oButton, "click")

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Take a look at the remarks for _IEFormSubmit... there is Javascript on the Go button that does more than a Submit.

;get the elements for adding next destination
$maps=_ieformgetobjbyname($mqobj,"loc2-form")
$address=_ieformelementgetcollection($maps,1)

;set and submit the next destination
_ieformelementsetvalue($address,"Las Vegas, NV")
msgbox(0,"",_ieformelementgetvalue($address))         ;test to make sure value has changed
$oButton = _IEGetObjById($mqobj, "loc2-button")
_IEAction($oButton, "click")

Dale

I didn't originally spot _IEGetObjByID() in the list of UDFs. That makes a lot of sense. Works fine now, too.

Share this post


Link to post
Share on other sites

Take a look at the remarks for _IEFormSubmit... there is Javascript on the Go button that does more than a Submit.

Question about this: How did you find out that there was extra Javascript associated with the Go button? I didn't see it when I viewed the source or when I checked it out with DebugBar, although maybe I just don't know what to look for.

Share this post


Link to post
Share on other sites

Question about this: How did you find out that there was extra Javascript associated with the Go button? I didn't see it when I viewed the source or when I checked it out with DebugBar, although maybe I just don't know what to look for.

Good question... it was actually an assumption based on behavior. You're right, there is none tied directly to the button. The other issue that is documented in the remarks of _IESubmit is that it does not send a button value, which may be used by the action page. This too is an assumption, but I can think of no other cause of the behavior. I seldom use _IEFormSubmit but rather use the "click" action as it is much more reliable.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Bump.

It seems that Mapquest has changed the code on their home page so that it's no longer possible to automate getting directions it with IE.au3. Or at least I can't figure out how to do it. The form on the page for getting directions is:

<form class="getDirsForm" id="getDirsForm" action="/maps" onsubmit="return false;">
                            <fieldset class="startFields" id="startFields">
                                <legend>Start</legend>
                                <div class="msg"></div>
                                <div id="getDirectionsRegion"></div>
                                <div id="startFormFields">  </div>
                                <div id="dirsTwoFiveToggle"></div>
                            </fieldset>
                            <div id="getDirsReverse"><div class="icon" title="Swap Locations"></div></div>
                            <fieldset class="endFields" id="endFields">
                                <legend>End</legend>
                                <div></div>
                                <div id="endFormFields"></div>
                                <div id="directionsOptions"></div>
                                <input type="submit" class="btn" value="Get Directions" id="dirSubmitButton" />
                            </fieldset>
                            <div class="cb"></div>
                        </form>

which doesn't offer any options for entering things like address, zip code, etc. Maybe I'm misreading the HTML; does anyone see a way to enter that data on the Mapquest page?

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0