alienclone

IE, Google Maps API, and JavaScript help

8 posts in this topic

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



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

1 person likes this

Share this post


Link to post
Share on other sites
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

#4 ·  Posted (edited)

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

#5 ·  Posted (edited)

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
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

1 person likes this

Share this post


Link to post
Share on other sites
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

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

    • Spask
      By Spask
      Hi, I'm trying to find a text value inside of a html.
      This is what the line looks like normally:
      <p id="line1" class> <span class="bot">TEXT HERE</span> </p> The text then changes to a non breaking space:
      <p id="line1" class> <span class="bot">&nbsp;</span> </p> And then it changes back to normal text but it's different every time.
      Can I code this so that it grabs the text every time it changes and has a variable that represents it?
      I currently have this inside of my loop:
      $span = .document.getElementsByTagName("span") For $text In $span If $text.value = "&nbsp;" Then Sleep(50) MsgBox(0,0,0) ;messagebox to test if it can be found, but I don't know how to grab the text EndIf Next The problem is that there are many other lines in the html that have the same span but are called "line3", "line5", etc and the one I need is from "line1".
      I will appreciate if anyone can help with this!
    • electrons
      By electrons
      hi  , hope  you all doing well 
       cant find any elements on the page ?  and the right click mouse dont work too?
      iam trying with more than method , i need help please!!
       

    • ur
      By ur
      I have kept below line to wait for IE to load the site completely and continue.
      _IELoadWait($oIE)
       
      But, the code is continuing without waiting for it and I my execution is failing as the elements are not loaded completely.

       
      Any suggestions for alternate code to wait for the browser to load completely?
       
    • ur
      By ur
      We can select elements in IE using their IDs as below.
      Local $oDiv = _IEGetObjById($oIE, "x-auto-16-input") But to one button in the webpage, there is no ID to it.
      In selenium we have option to select this element using the CssSelector and clicked the button using below code in c# selenium.
      driver.FindElement(By.CssSelector("button.x-btn-text")).Click(); What is the alternative for this in AUtoIT?
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I worked a bit on a little project of mine, and I managed to do what I was trying to do, or, automate a quiz in AutoIt.
      Now, everything works fine but, in order to achieve what I'm trying to achive, I'd like to make this script run faster.
      I'll attach a portion of the code in order to let you understand what my script does.
      $objIE_h1 = _IETagNameGetCollection($objIE, "h1") ; Take the text of the answer If @error Then ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF) Else For $objElement In $objIE_h1 $strInnerText = $objElement.innerText Next Select Case StringInStr($strInnerText, "QUESTION") ; Here is the question ; PS4 PRO $objSpans = _IETagNameGetCollection($objIE, "span") ; Answers are stored here For $objElement In $objSpans If $i >= 4 Then $strAnswer = $objElement.innerText ; Take the text of the answer n° 0, 1, 2, 3 If StringInStr($strAnswer, "CORRECT ANSWER") Then ; If I match the correct answer, then, I have to click on the input with answer id = answer_i $j = $i - 4 $objInput = _IEGetObjById($objIE, "answer_" & $j) If @error Then ConsoleWrite("Errore durante la lettura della risposta #" & $i & " - Errore: " & @error & @CRLF) Else _IEAction($objInput, "click") If @error Then ConsoleWrite("Errore durante il click sull'elemento. - Errore: " & @error) Else ConsoleWrite($j & ") Risposta: " & $strAnswer & @CRLF) ExitLoop EndIf EndIf EndIf $i+=1 Else $i+=1 EndIf Next $i = 0 $j = 0 This is what my script does.
      Questions are 20, in which I have 15 multiple choice question, 2 images ( on which I use _IEImgClick() ), and 3 text inputs ( a simple send with the text I have to enter ).
      How can I make all of these, faster?
      If I reach this goal, I've probably done one of my best goals in life, and I'd like to share my happiness with you, giving a huge donation to this fantastic community!
      Thanks for your help