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

    • nassausky
      By nassausky
      Hi all,
       
      Anyone have any idea how to close all open tabs except a specific one I manually open.  Assuming I don't know what is open in all the tabs except just the one I want to keep open.
       
      I didn't want to use sendkeys and I was trying to use the following code to list the title (or url) of the 3 open tabs and  after I got that part working I would just close the other 2. This sample only displays the title of the first open tab
      #include <IE.au3> Const $ie_new_in_tab = 0x0800 $oIE = _IECreate("https://www.autoitscript.com") __IENavigate($oIE, "https://www.autoitscript.com/forum/", 1, $ie_new_in_tab) ;(obj,url,wait,param) __IENavigate($oIE, "https://www.google.com/", 1, $ie_new_in_tab) ;(obj,url,wait,param) Local $aIE[1] $aIE[0] = 0 Local $i = 1, $oIE While 1     $oIE = _IEAttach("", "instance", $i)     If @error = $_IEStatus_NoMatch Then ExitLoop     ConsoleWrite(_IEPropertyGet($oIE, "title") & @CRLF)     ReDim $aIE[$i + 1]     $aIE[$i] = $oIE ;each item holds object     $aIE[0] = $i ;first item holds count     $i += 1 WEnd MsgBox($MB_SYSTEMMODAL, "Browsers Found", "Number of browser instances in the array: " & $aIE[0]) ; This doesn't return the list of tabs in the console just the first tab  
      Thanks for any and all help
    • toto22
      By toto22
      I'm trying to click on Java Dropbox using IE. However, I'm running into problems. There is a Dropbox "Please Select" with two options "Buy" and "Sell".
      I'm able to click on a drop box (please see code below) but i'm unable to select "Buy" or "Sell"".
      Local $sMyString = "Please Select" ;############ ENTER ############# Local $oLinks = _IELinkGetCollection($oIE) For $oLink In $oLinks Local $sLinkText = _IEPropertyGet($oLink, "innerText") If StringInStr($sLinkText, $sMyString) Then _IEAction($oLink, "click") ExitLoop EndIf Next  
      Please help
       
         
    • Gowrisankar
      By Gowrisankar
      Hello everyone,
      I'm working on a task where, a PDF file is opened (in IE browser) when I click a link in a website.
      I have to read the first page of the PDF to find particular strings. Can you please share some ideas?
    • Seminko
      By Seminko
      Hey,
      i would like to set a value into an INPUT field.
      Checked the _IEFormElementSetValue function but that does require _IEFormGetObjByName and this is where the problem comes in. The input field I want to write to is not a part of a form tag. It is part of a table.
      <input type="text" class="w2" id="nabidka_vozidel_formular_tach_od" name="nabidka_vozidel_formular_tach_od" onchange="GLOBAL.pocetInzerceNZ(&quot;nabidka_vozidel_formular&quot;,&quot;tach_od&quot;,&quot;&quot;);" autocomplete="off"> I tried this but that didn't work:
      $oDownloadSamples = _IEGetObjById($oIE, "nabidka_vozidel_formular_tach_od") _IEFormElementSetValue($oDownloadSamples, "123") If you want to try the site I'm working with is https://www.tipcars.cz/. There is a menu on the top left hand side and if you click the "vyhledat" button the input fields will show up.
      Thanks
    • Seminko
      By Seminko
      I am now able to populate the dropdown menus at https://www.tipcars.com/.
      The dropdowns are dynamic and do not have a Text value, only ids.
      Is there a way to get all the available options from a dropdown?
      $url = "https://www.tipcars.com/" $oIE = _IECreate($url) _IELoadWait($oIE) $oDownloadSamples = _IEGetObjById($oIE, "homepage_vyhl_frm_vozidlo") _IEFormElementOptionSelect($oDownloadSamples, "C") Above code, populates ID 'C' into the 'druh' dropdown, which results in selecting 'užitkové'. 
      Is there a way so I can grab all of the options from the dropdown menu? I could easily grab all the IDs but I am afraid they will change in the future so I would much rather match the text titles and assign the option IDs grabbed from site.
      This is what the options are according to Chrome:
      <select class="w1"id="homepage_vyhl_frm_vozidlo"name="homepage_vyhl_frm_vozidlo"onchange="try{NABIDKA_VOZIDEL_FORMULAR.naplnSelectZnacka('homepage_vyhl_frm');GLOBAL.pocetInzerceHZ('homepage_vyhl_frm','vozidlo');}catch(ex){odeslatJsChybu('formHOMEPAGE onChange 1: ' + ex.message, 'formHomePage onChange 1', -1);}"> <option value="A" style="color: black;">osobní a terénní (56 334)</option> <option value="C" style="color: black;">užitkové (4 333)</option> <option value="D" style="color: black;">nákladní (3 742)</option> <option value="E" style="color: black;">autobusy (56)</option> <option value="F" style="color: black;">obytné (373)</option> <option value="G" style="color: black;">přívěsy (1 179)</option> <option value="J" style="color: black;">motorky (780)</option> <option value="S" style="color: black;">pracovní stroje (605)</option> <option value="L" style="color: black;">ostatní (235)</option></select> Also, this cannot be grabbed by _INetGetSource.
      Thanks