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

    • ur
      By ur
      For the below form, I am able to automate using below code for textboxes.

      #include <IE.au3> Local $oIE = _IEAttach("http://localhost:18170/MartAdmin/", "url") _IELoadWait($oIE) $Search = _IEGetObjById($oIE,"x-auto-16-input") _IEPropertySet($Search, 'innerText','Uday KIran') $Search = _IEGetObjById($oIE,"x-auto-18-input") _IEPropertySet($Search, 'innerText','Uday KIran') But for the Login button, there is no id or name.
      The html code when I click on Inspect element in browser, shown below.
      <button tabindex="0" class="x-btn-text" style="width: 64px; position: relative;" type="button">Log In</button> Please let me know how to click this.?
       
    • jonson1986
      By jonson1986
      Hey,
      I'm trying to select language from drop-down menu on a webpage by _IEGetObjById but it's  not working, It mean autoit open the page but unable to select my desired value not even by matching text or by value, I'm looking for kind help...I've pastes my Autoit codes below along with source codes(using ie) of the webpage ;
      #include <IE.au3> $site = "http://example.com/upload" $oIE = _IECreate($site) $oDownloadSamples = _IEGetObjById($oIE, "language") $oDownloadSamplesSelect = _IETagNameGetCollection($oDownloadSamples, "select", "language") $oDownloadSamplesSelect.focus _IEFormElementOptionSelect($oDownloadSamplesSelect, "French", 1, "byText") Sleep (1000) _IEFormElementOptionSelect($oDownloadSamplesSelect, "2", 1, "byValue") HTML Codes using IE:
      <html> <head> <div class="form-row"> <div class="col-7"> <label>Language</label> <select name="language" class="select" id="language"> <option value="1">English</option> <option value="2">French</option> <option value="3">German</option> <option value="4">Italian</option> <option value="5">Japanese</option> <option value="6">Spanish</option> <option value="7">Russian</option> <option value="8">Hindi</option> <option value="9">Arabic</option> <option value="10">Chinese</option> <option value="11">Dutch</option> <option value="12">Finnish</option> <option value="13">Korean</option> <option value="14">Norwegian</option> <option value="15">Portuguese</option> <option value="16">Romanian</option> <option value="17">Serbian</option> <option value="18">Croatian</option> <option value="20">Polish</option> <option value="21">Afar</option> <option value="22">Abkhazian</option> <option value="23">Afrikaans</option> <option value="24">Amharic</option> <option value="25">Assamese</option> <option value="26">Aymara</option> <option value="27">Azerbaijani</option> <option value="28">Bashkir</option> <option value="29">Belarusian</option> <option value="30">Bulgarian</option> <option value="31">Bihari</option> <option value="32">Bislama</option> <option value="33">Bengali/Bangla</option> <option value="34">Tibetan</option> <option value="35">Breton</option> <option value="36">Catalan</option> <option value="37">Corsican</option> <option value="38">Czech</option> <option value="39">Welsh</option> <option value="40">Danish</option> <option value="41">Bhutani</option> <option value="42">Greek</option> <option value="43">Esperanto</option> <option value="44">Estonian</option> <option value="45">Basque</option> <option value="46">Persian</option> <option value="47">Fiji</option> <option value="48">Faeroese</option> <option value="49">Frisian</option> <option value="50">Irish</option> <option value="51">Scots/Gaelic</option> <option value="52">Galician</option> <option value="53">Guarani</option> <option value="54">Gujarati</option> <option value="55">Hausa</option> <option value="56">Hungarian</option> <option value="57">Armenian</option> <option value="58">Interlingua</option> <option value="59">Interlingue</option> <option value="60">Inupiak</option> <option value="61">Indonesian</option> <option value="62">Icelandic</option> <option value="63">Hebrew</option> <option value="64">Yiddish</option> <option value="65">Javanese</option> <option value="66">Georgian</option> <option value="67">Kazakh</option> <option value="68">Greenlandic</option> <option value="69">Cambodian</option> <option value="70">Kannada</option> <option value="71">Kashmiri</option> <option value="72">Kurdish</option> <option value="73">Kirghiz</option> <option value="74">Latin</option> <option value="75">Lingala</option> <option value="76">Laothian</option> <option value="77">Lithuanian</option> <option value="78">Latvian/Lettish</option> <option value="79">Malagasy</option> <option value="80">Maori</option> <option value="81">Macedonian</option> <option value="82">Malayalam</option> <option value="83">Mongolian</option> <option value="84">Moldavian</option> <option value="85">Marathi</option> <option value="86">Malay</option> <option value="87">Maltese</option> <option value="88">Burmese</option> <option value="89">Nauru</option> <option value="90">Nepali</option> <option value="91">Occitan</option> <option value="92">(Afan)/Oromoor/Oriya</option> <option value="93">Punjabi</option> <option value="94">Pashto/Pushto</option> <option value="95">Quechua</option> <option value="96">Rhaeto-Romance</option> <option value="97">Kirundi</option> <option value="98">Kinyarwanda</option> <option value="99">Sanskrit</option> <option value="100">Sindhi</option> <option value="101">Sangro</option> <option value="102">Serbo-Croatian</option> <option value="103">Singhalese</option> <option value="104">Slovak</option> <option value="105">Slovenian</option> <option value="106">Samoan</option> <option value="107">Shona</option> <option value="108">Somali</option> <option value="109">Albanian</option> <option value="110">Siswati</option> <option value="111">Sesotho</option> <option value="112">Sundanese</option> <option value="113">Swedish</option> <option value="114">Swahili</option> <option value="115">Tamil</option> <option value="116">Telugu</option> <option value="117">Tajik</option> <option value="118">Thai</option> <option value="119">Tigrinya</option> <option value="120">Turkmen</option> <option value="121">Tagalog</option> <option value="122">Setswana</option> <option value="123">Tonga</option> <option value="124">Turkish</option> <option value="125">Tsonga</option> <option value="126">Tatar</option> <option value="127">Twi</option> <option value="128">Ukrainian</option> <option value="129">Urdu</option> <option value="130">Uzbek</option> <option value="131">Vietnamese</option> <option value="132">Volapuk</option> <option value="133">Wolof</option> <option value="134">Xhosa</option> <option value="135">Yoruba</option> <option value="136">Zulu</option> <option value="19">Other</option> </select> </div> </main> </body> </html>  
    • kawliga751
      By kawliga751
      I am trying to script the opening of multiple tabs in IE with each tab having a separate login/password. I have been able to make a successful script that will open 3 separate IE sessions with the correct webpage and login or a script that will open 3 tabs in one session (which I want) but will not login. I have tried _IECreate, IEAttach etc. This is the script I am currently using . 
      #include <IE.au3> Const $navOpenInNewTab = 0x0800 Dim $oIE = _IECreate('http://asag.xxxxxxx.com/AAAA/index.htm') ;$o_IE.Navigate2('http://asag.xxxxxxx.com/apps/yyyyyyy/LogInSAG/login.asp', $navOpenInNewTab) ;$o_IE.Navigate2('http://asag.xxxxxxx.com/apps/yyyyyyy/LogInSAG/login.asp', $navOpenInNewTab) Call ("YYYYYYYSignIn") Func YYYYYYYSignIn () Local $username = _IEGetObjByName ($oIE,"uname") Local $password = _IEGetObjByName ($oIE,"pword") $oIE.Navigate2('http://asag.xxxxxxx.com/apps/xxxxxxx/LogInSAG/login.asp',2048) _IEFormElementSetValue ($username, "xxxxxxx") _IEFormElementSetValue ($password, "xxxxxxx") Send('{Enter}') EndFunc Call ("xxxxxxxSignIn") Func xxxxxxxSignIn () __IENavigate($oIE, "https://soa1gui.xxxxxxx.biz/gateway/NFServlet;jsessionid=1E3B8F6520DE0A1EC914A8ABB7E86341?NFH_MessageId=&NFH_Page=%2fpages%2fsearch%2fsearch.jsp", 1, 0x800) Local $domain = _IEGetObjByName ($oIE,"NF_CustomerID") Local $User_Name = _IEGetObjByName ($oIE,"NF_UserName") Local $Password = _IEGetObjByName ($oIE,"NF_Password") _IEFormElementSetValue ($domain, xxxxxxx") _IEFormElementSetValue ($User_Name, "xxxxxxx") _IEFormElementSetValue ($Password, "xxxxxxx") ;Send('{Enter}') EndFunc  
    • milos83
      By milos83
      How can I check if element is focused in Firefox using FF.au3 UDF?
      This is my try:
      I have prepared a function that checks if the object is focused:
       
      _FFCmd('FFau3.isfocused=function isfocused(a){try{return (a === document.activeElement)}catch(e){return}}') $oElm = _FFXPath("//*[@id='someId']") ConsoleWrite(_FFIsFocused($oElm)) Func _FFIsFocused($sElement = "") Local $isFoc = _FFCmd("FFau3.isfocused(" & $sElement & ")") Return $isFoc EndFunc ;==>_FFIsFocused Now, the javascript part is tested and it does return successfully.
      After a lot of try/fails I inserted an alert box in order to display the object being compared.
      Here is what I got
       
      The focused object is: [object XULElement]
      The object that I send for comparing is [object HTMLInputElement]
      Why is that?
       
       
    • slidy56fr
      By slidy56fr
      Internet Explorer 11, AutoIt 3.3.14.2
      I want to download many files which are published with hyperlink on a web page. I use AutoIt and when there is a few files, it works even if It's on a website with secured links.
      I have a script to download link items with the object method (I gave a partial sample), but when the number of link exceed the web page, there is not an auto scroll, then the links which are not on displayed without scroll are not downloaded.
      Thank you
      From France
       
       
      EchantillonRecepAnonym.au3