Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Basic Webpage Controls with JavaScript / COM - Tutorial


  • Please log in to reply
335 replies to this topic
Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

It's a good teaching style to have if people have plenty of time to spend working on code. I personally learn best through example and a quick explanation, and then I know how to convert that to what I need in a particular case.

 

What's getting me right now is just doing an automatic tweet on twitter. The box is "<div id="tweet-box-mini-home-profile" class="tweet-box rich-editor notie" contenteditable="true" aria-multiline="true" role="textbox" spellcheck="true" aria-labelledby="tweet-box-mini-home-profile-label" dir="ltr" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" aria-controls="typeahead-dropdown-4"></div>"

 

Using the iWB2 Learner tool, it returned to me the bolded. How do I go about targeting this? I'm at wb.document.all.tweet_box_mini_home_profile.value := Test Tweet which does not work. I found that AHK does not accept - in the class name, so I tried just replacing them with underscores. I can launch the script, but it runs into an error when it tries to search it on the webpage - of course because there is no field by that particular name with underscores.

 

If I use the name as is:

 


---------------------------
Anarchy Sophisticated.ahk
---------------------------
Error at line 8.

Line Text: wb.document.all.tweet-box-mini-home-profile.value := "Test Tweet"
Error: This line does not contain a recognized action.

The program will exit.
---------------------------
OK   
---------------------------



jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
wb.document.getElementById("tweet-box-mini-home-profile").value


hubs
  • Members
  • 9 posts
  • Last active: Jun 27 2014 07:19 AM
  • Joined: 06 May 2014

Hi,

 

I having trouble with this. I started off well but know I'm stuck. I am trying to automate this page. It loads as an about:blank page after firing off a javascript function on another page. I don't know if about:blank pages need to be treated differently. I tried saving the html to file and loading that but I still couldn't read, set values or fire off any javascripts on it.

 

here is the html with javascript stripped out... 

<HTML><HEAD>
</script><title>Zoom to Coordinate</title><link rel="stylesheet" type="text/css" href="RightWebMap.css"><body><div id="content"><h3>Zoom to Coordinate</h3><form action="#" name="zoomForm" id="zoomForm"><table><tr><td><strong>Type:</strong></td><td><select name="ZoomType" id="ZoomType" onChange="setDegree(this.value)"></select><span id="degreeExample"></span></td></tr><tr><td><strong>Window:</strong></td><td><select name="zoomWindow" id="zoomWindow" onChange="setWindowTypeParameters(this.value);"></select></td></tr><tr><td id="useCurrentText"></td><td id="scaleText"></td></tr><tr><td id="zoneText"><td></td></td></tr><tr><td colspan="2"><table><tr><td></td><td id="nwCorner"><strong>North-West Corner</strong></td><td></td><td id="seCorner"><strong>South-East Corner</strong></td></tr><tr><td id="longText">Longitude</td><td><input type="text" name="longValue" size="10" value=""></td><td id="longText2">Longitude</td><td id="longText2Form"><input type="text" name="longValue2" size="10" value=""></td></tr><tr><td id="latText">Latitude</td><td><input type="text" name="latValue" size="10" value=""></td><td id="latText2">Latitude</td><td id="latText2Form"><input type="text" name="latValue2" size="10" value=""></td></tr></table></td></tr><tr><td><input type="button" name="Submit" value="Zoom" onClick="rZoomCoordinates.zoom()"></td><td><input type="reset" value="Reset" onClick="setDegree();setWindowTypeParameters(0);"></td></tr></table></form></div><br><div id="controlBottom" style="position:absolute; bottom: 10px;left: 10px;"></div> </body></html>

I have tried setting values...

wb := IEGet("Zoom to Coordinate")
wb.document.getElementsByName("longValue")[0].value := "1234"

I have tried ...

wb.document.all.longValue.Value := "1234512345"

and countless others. But nothing works on this page.

 

I would greatly appreciate any help. I would really like to get this to work.

Mike

 

Edit/  Apologies if this was the wrong place for this. I later thought it more appropriate under the support forum. Anyhow I solved my problem and managed to avoid needing to automate any of the web page referenced in this post.

 

 


Edited by hubs, 15 May 2014 - 03:06 PM.


gazylion
  • Members
  • 3 posts
  • Last active: May 24 2014 02:22 PM
  • Joined: 22 May 2014

Hi!

 

I'm trying to fill submit registration form one site: https://www.gmailbox.org/signUp, below is my code:

Username := "RandomUsername"
FirstName := "RandomFirstName"
LastName := "RandomLastName"
Password := "RandomPassword"
Email := "RandomEmail@random.com"
If !IsObject(ie)
    ie := ComObjCreate("InternetExplorer.Application")
ie.Visible := true
ie.Navigate("https://www.gmailbox.org/signUp")
While !(ie.busy)
    Sleep, 100
While (ie.busy)
    Sleep, 100
While !(ie.document.Readystate = "Complete")
    Sleep, 100
ie.document.getElementsByTagName("INPUT")[0].Value := Username
ie.document.getElementsByTagName("INPUT")[1].Value := FirstName
ie.document.getElementsByTagName("INPUT")[2].Value := LastName
ie.document.getElementsByTagName("INPUT")[3].Value := Password
ie.document.getElementsByTagName("INPUT")[4].Value := Password
ie.document.getElementsByTagName("INPUT")[5].Value := Email
ie.document.getElementsByTagName("INPUT")[7].Checked := 1
ie.document.getElementsByTagName("BUTTON")[2].Click()
While !(ie.busy)
    Sleep, 100
While (ie.busy)
    Sleep, 100
While !(ie.document.Readystate = "Complete")
    Sleep, 100

After submiting form it tells me that form fields are empty:

SignUpForm.JPG

 

Is there a function, that i should run after filling forms?

(sorry for my english)



capeably
  • Members
  • 61 posts
  • Last active: Jun 10 2016 06:50 AM
  • Joined: 18 May 2013

Hi.  I'm very new to AHK, so my apologies if this is a stupid question. 

 

I am trying to learn how to control web pages with AHK, so I'm very interested this subject matter. However, I'd like to make sure this is the right place for me to start.

 

My questions:

  • As this tutorial is a couple years old, is it still relevant to the most recent version of IE?
  • Will this help me if I want to use Firefox or Chrome instead of IE? Or is this only relevant to IE?

Thank you.



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
  • As this tutorial is a couple years old, is it still relevant to the most recent version of IE?

Yes its still relevant.

  • Will this help me if I want to use Firefox or Chrome instead of IE? Or is this only relevant to IE?


No! This is only for IE but it may help you later if you like to learn to use COM with other programs that also support it.
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

Lobotom1
  • Members
  • 1 posts
  • Last active: Oct 27 2014 03:44 PM
  • Joined: 24 Oct 2014

Hi,

 

While browsing this topic, I tried to control some java application inside internet explorer we use at work. I got stuck at the beginning of the search using IWB2 learner as the getElementById of the inputbox I wanted to populate changed at each page reload.

 

 

Finally I found one description that stayed the same : found using the "show parent structure of the iwb2 learner. There is one  DIV id="form.param.socialPrestProfIncomes_control"

 

The code from the webpage:

PARENT: <div class="v-filterselect v-widget v-has-width v-filterselect-prompt" id="form.param.socialPrestProfIncomes_control" role="combobox" style="width: 100%;">

 

Child : <input style="width: 100%;" id="gwt-uid-332" class="v-filterselect-input" tabIndex="0" aria-labelledby="gwt-uid-331" type="text"><div aria-hidden="true" class="v-filterselect-button" role="button"></div>

 

 

Can someone tell me which code I should use to insert a value in this "child"field  for which the id change all the time but not the parent id?

 

Many Thanks,

 

Lobo.



smorgasboard
  • Members
  • 660 posts
  • Last active: Jan 14 2016 08:53 AM
  • Joined: 18 Jul 2012

subscribing. 



pensaer
  • Members
  • 23 posts
  • Last active: Aug 04 2015 01:19 AM
  • Joined: 06 Apr 2015

the all property is no longer supported in IE11

and drop down selection don't work for me

maybe somebody can solve this problem:

 

...

wb.document.GetElementById("level1-option").selectedIndex="kunstantiek"

...

 

this is what I got from the website:

 

<div class="categories-wrapper ">

   <div data-custom-select >

      <label for="level1-option" class="has-hidden-label">Afdeling</label>

      <select class="categories-options" data-level="1" name="level1-option" id="level1-option" >

         <option value="">Kies afdeling</option>

         <option value="kunstantiek"

                      data-href="/callback/discovery/kunstantiek/">Antiek &amp; Art</option>

         <option ....

 



pensaer
  • Members
  • 23 posts
  • Last active: Aug 04 2015 01:19 AM
  • Joined: 06 Apr 2015

Hi!

 

I'm trying to fill submit registration form one site: https://www.gmailbox.org/signUp, below is my code:

Username := "RandomUsername"
FirstName := "RandomFirstName"
LastName := "RandomLastName"
Password := "RandomPassword"
Email := "RandomEmail@random.com"
If !IsObject(ie)
    ie := ComObjCreate("InternetExplorer.Application")
ie.Visible := true
ie.Navigate("https://www.gmailbox.org/signUp")
While !(ie.busy)
    Sleep, 100
While (ie.busy)
    Sleep, 100
While !(ie.document.Readystate = "Complete")
    Sleep, 100
ie.document.getElementsByTagName("INPUT")[0].Value := Username
ie.document.getElementsByTagName("INPUT")[1].Value := FirstName
ie.document.getElementsByTagName("INPUT")[2].Value := LastName
ie.document.getElementsByTagName("INPUT")[3].Value := Password
ie.document.getElementsByTagName("INPUT")[4].Value := Password
ie.document.getElementsByTagName("INPUT")[5].Value := Email
ie.document.getElementsByTagName("INPUT")[7].Checked := 1
ie.document.getElementsByTagName("BUTTON")[2].Click()
While !(ie.busy)
    Sleep, 100
While (ie.busy)
    Sleep, 100
While !(ie.document.Readystate = "Complete")
    Sleep, 100

After submiting form it tells me that form fields are empty:

SignUpForm.JPG

 

Is there a function, that i should run after filling forms?

(sorry for my english)

 

maybe it's too quick for it



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012

maybe it's too quick for it

more Likly to be an eventlistner event not being fired.

Also in your example in the post before you use an = but you need to use an := to make it work and select index needs a number not a string to set the option with a string you need to set the value of the select element
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

pensaer
  • Members
  • 23 posts
  • Last active: Aug 04 2015 01:19 AM
  • Joined: 06 Apr 2015

more Likly to be an eventlistner event not being fired.

Also in your example in the post before you use an = but you need to use an := to make it work and select index needs a number not a string to set the option with a string you need to set the value of the select element

 

it's selecting now but it doesn't change to that option it stays the same but when I open it you can see it selected another option

I don't understand WHYY

 

EDIT: well, I fixed it but still programming shouldn't be so complex



Hacktivator
  • Members
  • 15 posts
  • Last active: Jul 21 2015 09:06 AM
  • Joined: 27 Dec 2014

1.if i want to access class what would i do?

2.if i want to access href what would i do?

 

1,example:

<a class="example" >

 

2. <a href="example">



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012

1.if i want to access class what would i do?
2.if i want to access href what would i do?
 
1,example:
<a class="example" >
 
2. <a href="example">


It depends on what your really try to do...

Do you already have an element or are you looking for an element with that attribute

already have:
msgbox % Element.classname
find element:
wb := WBGet()
links := wb.document.links
loop % links.length
{
    if (links[A_index-1].href = "http://www.google.com")
    {
        links[A_index-1].click()
        break
    }
}
return


WBGet(WinTitle="ahk_class IEFrame", Svr#=1) {               ;// based on ComObjQuery docs
   static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
        , IID := "{0002DF05-0000-0000-C000-000000000046}"   ;// IID_IWebBrowserApp
;//     , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}"   ;// IID_IHTMLWindow2
   SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%
   if (ErrorLevel != "FAIL") {
      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
         return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
      }
   }
}
But to really help you, I need better info...
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

10basetom
  • Members
  • 9 posts
  • Last active: May 12 2015 06:00 PM
  • Joined: 03 Jul 2007

I so wish one day we'll have a COM for PhantomJS *drool*.