Jump to content
alienclone

IE, Google Maps API, and JavaScript help

Recommended Posts

alienclone

Hello All,

I am looking for a smoother and less intrusive way to complete my task.

My current code does what I need...

Spoiler
#include <IE.au3>
$oIE = _IECreate("about:blank")
_IENavigate($oIE, "http://spp.aaa.com/15.0.14/D2000Map/loadMap.html")
$oIE = _IEAttach("Mapping")
WinWait("Mapping")
WinActivate("Mapping")

;=========================================================== current method to set view to Streets
$oDiv = _IEGetObjById($oIE, "OpenLayers_Control_MaximizeDiv")
Sleep(500)
_IEAction($oDiv, "focus")
Sleep(90)
ControlSend("Mapping", "", "", "{enter}")

$oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
    $sLinkText = _IEPropertyGet($oInput, "outerhtml")
    If StringInStr($sLinkText, "Google Streets") Then
        $oInput.Focus()
        Sleep(500)
        ControlSend("Mapping", "", "", "{enter}")

    EndIf
Next

$oDiv = _IEGetObjById($oIE, "OpenLayers_Control_MinimizeDiv")
Sleep(500)
_IEAction($oDiv, "focus")
Sleep(90)
ControlSend("Mapping", "", "", "{enter}")


;======================================================== current method for centering and zooming map

Sleep(1000)
$oDiv = _IEGetObjById($oIE, "OpenLayers_Control_PanZoomBar_53_zoomout")
Sleep(500)
_IEAction($oDiv, "focus")
Sleep(500)
ControlSend("Mapping", "", "", "{enter}")

$oDiv = _IEGetObjById($oIE, "OpenLayers_Control_PanZoomBar_53_panup")
Sleep(500)
_IEAction($oDiv, "focus")
Sleep(500)
ControlSend("Mapping", "", "", "{enter}")

 

But I am wanting to work more "behind the scenes".

By looking at the JavaScript found at the source, i'm guessing there is a third party program called OpenLayers working with the Google Maps API.

I was wondering if there was a way to manipulate the JavaScript or the Document Object Models in an IE window that I did not create (opened by another program).

I know VERY LITTLE outside of simple AutoIt code and UDFs that I am not even sure if what I just said makes sense.

My 3 days of research and "patchwork" of attempted code created from examples and "trial and error guesses" ended in confusion

and a "crime of passion" (frustratingly erasing ALL attempts because they were wrong, confusing, didn't work, gave me a migraine, resembled Frankenstein's monster,

filled me with anger and hatred and a shame so deep that I stood in a hot shower for 30 minutes trying to wash it away).

I think my main problem is not knowing if this is possible, and the proper syntax for manipulating DOM from within AutoIt.

  • The ACTUAL window I am working with is an Internet Explorer_Server window opened by a program that passes my credentials and other info to it. So I have to stick with IE.
  • The IE page in my example code above is just the source, NOT the window I am tying to automate, it is identical except the bottom bar doesn't seem to send to the server so I'm not sure if it can even be used for testing purposes.

 

Any insight in non-programmer terms or some examples to show me the proper syntax will be greatly appreciated.

:alien:


if @error Then
	MsgBox(262192,"",@ComputerName&" slaps "&@UserName&" around a bit with a large trout!")
	EndIf

>Exit code: 0

REAL search results

"Yeah yeah yeah, patience. How long will that take?"  -Ed Gruberman

Share this post


Link to post
Share on other sites
AutoBert

are you sure Google maps allow manipulating data in the way you want?

  • Like 1

Share this post


Link to post
Share on other sites
alienclone
5 minutes ago, AutoBert said:

are you sure Google maps allow manipulating data in the way you want?

I think that is what the Google Maps API is for, I know you can use it to create your own map overlays the way the program i'm using does.

But I am not creating, I am trying to manipulate an already created map.

I am NOT sure if it works that way, that is why I asked IF it is possible in the first post.


if @error Then
	MsgBox(262192,"",@ComputerName&" slaps "&@UserName&" around a bit with a large trout!")
	EndIf

>Exit code: 0

REAL search results

"Yeah yeah yeah, patience. How long will that take?"  -Ed Gruberman

Share this post


Link to post
Share on other sites
alienclone

Progress!! Yay!

First, i'm pretty sure the link to the map I gave in my example code in first post is not "live" because I cant get it to accept ANYTHING. Therefore it doesn't seem possible that anyone here will be able to actually test anything.

BUT, I did manage to get something to work on the actual program that i'm using. So this...

$oIE.setCenterAndZoom(30.3144639, -81.67038, 10)

...replaces this...

Spoiler
$oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
    $sLinkText = _IEPropertyGet($oInput, "outerhtml")
    If StringInStr($sLinkText, $sMyString1) Then
        _IEFormElementSetValue($oInput, "8298 Riverview Drive")
    EndIf
Next
$oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
    $sLinkText = _IEPropertyGet($oInput, "outerhtml")
    If StringInStr($sLinkText, $sMyString2) Then
        _IEFormElementSetValue($oInput, "st augustine, FL")
    EndIf
Next
$oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
    $sLinkText = _IEPropertyGet($oInput, "outerhtml")
    If StringInStr($sLinkText, $sMyString3) Then
        _IEAction($oInput, "focus")
        Sleep(90)
        ControlSend("Bing Map", "", "", "{enter}")
    EndIf
Next
Sleep(1000)
$oDiv = _IEGetObjById($oIE, "OpenLayers_Control_PanZoomBar_53_zoomout")
Sleep(500)
_IEAction($oDiv, "focus")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
;ControlSend("Bing Map", "", "", "{enter}")
;Sleep(500)
$oDiv = _IEGetObjById($oIE, "OpenLayers_Control_PanZoomBar_53_panup")
Sleep(500)
_IEAction($oDiv, "focus")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")

 

 

Now I just need to figure out how to change the view from "Hybrid" to "Street" (or "ROADMAP" as I believe the Google Map API calls it).

The part that irritates me the most about this issue is that Google's default view IS "Street", but for some reason my work program felt the need to purposely change it although the main purpose of my work's map is to show the locations of our service trucks and the service call locations, there is no need for any "greenery" in our work functions.

This new default view just started Friday when they "updated" the program and switched from Bing maps to Google, but they didn't change the Window title if you are wondering why my script says Bing Map.

Edited by alienclone

if @error Then
	MsgBox(262192,"",@ComputerName&" slaps "&@UserName&" around a bit with a large trout!")
	EndIf

>Exit code: 0

REAL search results

"Yeah yeah yeah, patience. How long will that take?"  -Ed Gruberman

Share this post


Link to post
Share on other sites
alienclone

Ok, one step closer!

Managed to get my script to click the radio button for "Google Streets" without opening and closing the menu (plus sign "+" in top right edge of map).

It shows the radio button selected after the script runs. but it doesn't actually implement the action so the map stays in "Google Hybrid" view.

#include <IE.au3>
$oIE = _IECreate("about:blank")
_IENavigate($oIE, "http://spp.aaa.com/15.0.14/D2000Map/loadMap.html")
_IELoadWait($oIE)

WinWait("Mapping")

; ===> Temp "slow downs" until I can properly solve my premature script continuation issue
Sleep(900)
Do
    sleep(90)
    $url=$oIE.LocationURL
until $url<>""
Sleep(900)
; =========================

$oIE = _IEAttach("Mapping")

$oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
    $sLinkText = _IEPropertyGet($oInput, "outerhtml")
    If StringInStr($sLinkText, "Google Streets") Then
        $oInput.click()

    EndIf
Next

Tried using _IEFormElementRadioSelect to do this but I don't know how without finding an actual "Form" or "Radio Group" that it belongs to. If someone could help me find that, it would probably be the best route for this task, and easier than what I am currently attempting.

Edited by alienclone
shamelessly whispering @DaleHohm in hopes that his ears will ring and he comes to see who is talking about him (and help me find a solution using his magical IE powers)

if @error Then
	MsgBox(262192,"",@ComputerName&" slaps "&@UserName&" around a bit with a large trout!")
	EndIf

>Exit code: 0

REAL search results

"Yeah yeah yeah, patience. How long will that take?"  -Ed Gruberman

Share this post


Link to post
Share on other sites
Juvigy
var myOptions = {
  center: new google.maps.LatLng(39.729001, -94.902342),
  zoom: 3,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
setUpMarker(map);

And here is the api reference:

https://developers.google.com/maps/documentation/javascript/3.22/reference#MapTypeId

  • Like 1

Share this post


Link to post
Share on other sites
alienclone
10 hours ago, Juvigy said:
var myOptions = {
  center: new google.maps.LatLng(39.729001, -94.902342),
  zoom: 3,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
setUpMarker(map);

And here is the api reference:

https://developers.google.com/maps/documentation/javascript/3.22/reference#MapTypeId

I really appreciate you taking the time to go through all those JS files, and I am sorry that I didn't explain myself better in the first post.

But I already have all of this information, I just don't know how to integrate it with AutoIt and the proper syntax to call the functions on an existing IE window that has already loaded.


if @error Then
	MsgBox(262192,"",@ComputerName&" slaps "&@UserName&" around a bit with a large trout!")
	EndIf

>Exit code: 0

REAL search results

"Yeah yeah yeah, patience. How long will that take?"  -Ed Gruberman

Share this post


Link to post
Share on other sites
alienclone

Well I think I have decided to give up.

Not only did I not figure out how to change it to "Google Streets" (ROADMAP), but the one part I did manage to figure out...

$oIE.setCenterAndZoom(30.3144639, -81.67038, 10)

...only wants to work on some of the computers I am working with, and of course it gives no errors when it doesn't work.

I may revisit this project at a later time but an entire week of work to produce ONE unreliable line of code has discouraged me for now.

Thank you to  @AutoBert and @Juvigy for the responses.


if @error Then
	MsgBox(262192,"",@ComputerName&" slaps "&@UserName&" around a bit with a large trout!")
	EndIf

>Exit code: 0

REAL search results

"Yeah yeah yeah, patience. How long will that take?"  -Ed Gruberman

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

  • Similar Content

    • Seminko
      By Seminko
      Is there a way to grab non-hardcoded but rather javascript generated data from a webpage?
      Tried a get request as well as _IEBodyReadHTML but both seem to grab the code without the javascript generated data.
      $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", "link", False) $oHTTP.Send() $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status Global $DataArray[10][5] If $oStatusCode <> 200 Then Exit MsgBox(1, "Error", "Status Code <> 200") EndIf FileWrite(@ScriptDir & "\output.txt", $oReceived) ; //////// #include <IE.au3> Local $FullLink = "link" Local $oIE = _IECreate($FullLink, 0, 0) _IELoadWait($oIE) Local $sText = _IEBodyReadHTML($oIE) FileWrite(@ScriptDir & "\output.txt", $sText)  
    • FMS
      By FMS
      Hello,
      I try to get all the text from a news site around a subject.
      The first run I get all the text inside a attribute in an array.
      When i try to go back and reload another page it chrashes and think it because "$oIE.GoBack"
      I couldn't find anything in the help/forum around this subject.
      Do I need to reload the $oIE or something afther an X.GoBack?
      The error i got is :
      if $oTag2.GetAttribute("class") == "NewsDetail" Then if $oTag2^ ERROR I'm not shure why I got this error, maybe someone could explain?
      Also I'm open for some pointers in this test script because I'm pretty new in working whit the IE.UDF
      Maybe there is an simpler way to get the same results?

      test script:
      #include <IE.au3> #include <MsgBoxConstants.au3> #include <Array.au3> HotKeySet("{ESC}", "Terminate") Global $oIE = _IECreate("https://www.iex.nl/Zoeken/Nieuws.aspx?q=air%20france") ;get first subject Global $oLink1 = _IEGetObjById($oIE, "ctl00_ctl00_Content_LeftContent_NewsSearch_repNews_ctl00_linkNews") Sleep(500) _IEAction($oLink1, "click") Sleep(500) Global $oTags = _IETagNameGetCollection($oIE, "div") Global $aResults[1] For $oTag In $oTags if $oTag.GetAttribute("class") == "NewsDetail" Then _ArrayAdd($aResults, $oTag.innerTEXT) EndIf Next $aResults[0] = UBound($aResults) - 1 _ArrayDisplay($aResults, "Episodelist") ConsoleWrite($aResults[1] & @CRLF) $oIE.GoBack ;get second subject Global $oLink2 = _IEGetObjById($oIE, "ctl00_ctl00_Content_LeftContent_NewsSearch_repNews_ctl01_linkNews") Sleep(500) _IEAction($oLink2, "click") Sleep(500) Local $oTags2 = _IETagNameGetCollection($oIE, "div") Local $aResults2[1] For $oTag2 In $oTags2 if $oTag2.GetAttribute("class") == "NewsDetail" Then _ArrayAdd($aResults2, $oTag2.innerTEXT) EndIf Next $aResults2[0] = UBound($aResults2) - 1 ConsoleWrite($aResults2[1] & @CRLF) Func Terminate() _IEQuit($oIE) Exit EndFunc ;==>Terminate  
    • SkysLastChance
      By SkysLastChance
      I am having a hard time understanding why this is not working. I was hoping some one could help explain it to me. 
      $tags = $oIE.document.GetElementsByTagName("input") For $tag in $tags $class_value = $tag.GetAttribute("class") If string($class_value) = "fTs-p3298-l0 wplEditControl" Then $target = $tag ExitLoop EndIF Next MsgBox(0,"",$target) If $target = "fTs-p3298-l0 wplEditControl" THEN MsgBox(0,"","itworked") I have tried 
       MsgBox(0,"",$target.Attribute)  MsgBox(0,"",$target.Value)  MsgBox(0,"",$target.InnerText) I would expect to see this in the msgbox
      fTs-p3298-l0 wplEditControl  
    • SkysLastChance
      By SkysLastChance
      I am trying to grab the id "in2xk_26" however it the characters before the underscore always change. (in the name too)
      Is there a way I can find a id or name by the last 3 charcters?
      Using something like "stringright?"
      So I would want to search for just "_26" in this case.
      This is assuming that there are no other _26
       

      #include <Excel.au3> #include <IE.au3> #include <GUIConstantsEx.au3> Global $iMousespeed = 25,$target = "",$TagName = "",$Value = "",$Atrribute = "" $oIE = _IEAttach("MEDITECH") $TagName = "input" $Value = "in2xk_26" $Attribute = "id" $tags = $oIE.document.GetElementsByTagName($TagName) ;TagName ------ MAKE SURE TO NAME THESE For $tag in $tags $class_value = $tag.GetAttribute($Attribute) ;Attribute ------ MAKE SURE TO NAME THESE If string($class_value) = $Value Then ;Value ------ MAKE SURE TO NAME THESE $target = $tag $iScreenX = _IEPropertyGet($target, "screenx") $iScreenY = _IEPropertyGet($target, "screeny") $iWidth = _IEPropertyGet($target, "width") $iHeight = _IEPropertyGet($target, "height") $oMouseCords = MouseMove($iScreenX + $iWidth / 2, $iScreenY + $iHeight / 2, $iMousespeed) MouseClick($MOUSE_CLICK_LEFT) ExitLoop EndIf Next  
       
    • SkysLastChance
      By SkysLastChance
      I was wondering how I read data inside of a iframe. I would like to be able to click something inside a iframe. However, I can't even find the tag. 
      The id and name change all the time so I can't use those. 
      The code highlighted in blue is what I am trying to click. (second picture)
      Here is what I have tried.
      $target = "" $tags = $oIE.document.GetElementsByTagName("div") For $tag in $tags $class_value = $tag.GetAttribute("class") If string($class_value) = "s_92 altstyle s_93 s_94" Then $target = $tag ConsoleWrite("Tag Found " & $target.outerText&@CRLF) ExitLoop EndIf Next  

       
       

×