Jump to content

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

Automation IE7 Navigation and Scripting with Tabs


  • This topic is locked This topic is locked
214 replies to this topic

Poll: Do you find this group pf wrapper functions for IE Automation Usefull (35 member(s) have cast votes)

Do you find this group pf wrapper functions for IE Automation Usefull

  1. no you suck (3 votes [8.33%])

    Percentage of vote: 8.33%

  2. need better Documentation (10 votes [27.78%])

    Percentage of vote: 27.78%

  3. What is DHTML i dont understand how this helps (4 votes [11.11%])

    Percentage of vote: 11.11%

  4. I use Firefox this is a stupid idea (10 votes [27.78%])

    Percentage of vote: 27.78%

  5. I know DHTML this is a reasonably good AHK adaption (2 votes [5.56%])

    Percentage of vote: 5.56%

  6. This is the best DHTML too in the AHK Forum (7 votes [19.44%])

    Percentage of vote: 19.44%

Vote
rani
  • Members
  • 217 posts
  • Last active: Jul 21 2016 12:53 PM
  • Joined: 18 Mar 2008
Hi Tank,

ok, now I understand the functionality of JS and AHK


what remain:
how I find an instance of specific,web page documnet
let say in IE6 ?

rgrds
Ell

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
that is specifically what IE7_Get does
first page mid way down
returns a window handle equal to what you do with oWin in your example script
the difference is i reference shell explorer but for a windows box its perfect
oh i think i see your confusion the functions are IE7

lets be clear all these functions work equal on ie6 or ie7 with or without tabs
example lets say you have a google page open
COM_Init()
parentWindow:=IE7_Get("Google")
IE7_Set_DOM(parentWindow,"q","Automation IE7 Navigation and Scripting with Tabs")
IE7_Button_click(parentWindow,"Google Search")

does that clear that up
this works in ie 6 and 7 not just 7
works in 7 with or without tabs
Never lose.
WIN or LEARN.

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
many times i see posts wehre people want to disect a page
the following code has the following issues
traversing frames. at this time the dom viewer will not give you anything more than the frame atributes i might get to adding that soon
COM_Init()
COM_Error(false)
mouseover=
(
function whichElement()
{
   tname=event.srcElement.tagName;
   tindex=event.srcElement.sourceIndex;
   innerhtml=event.srcElement.innerHTML
   oAttrColl = event.srcElement.attributes;
   myLen=oAttrColl.length
   xx="Dom=document.all(" + tindex + ")\n";
   xx=xx + "document.all(" + tindex + ").tagName=" + event.srcElement.tagName + "\n";
   for (i = 0; i < oAttrColl.length; i++)
   {
      oAttr = oAttrColl.item(i);
      bSpecified = oAttr.specified;
      sName = oAttr.nodeName;
      vValue = oAttr.nodeValue;
      if (bSpecified)
      {
         xx=xx + sName + "=" + vValue + "\n";
      }
   }
   xx=xx + "document.all(" + tindex + ").value=" + event.srcElement.value + "\n";
   
}
document.body.onmouseover = whichElement
)

Gui, Add, Button, x6 y0 w90 h20 gResume, Resume
Gui, Add, Edit, x6 y20 w310 h315 vDom,

Gui, Show, h335 w320, DOM Extractor Ctrl + / to freeze
SetTimer,dom,800
Return

GuiClose:
ExitApp
Resume:
SetTimer,dom,800
Return
dom:
   WinGetTitle,thispage,ahk_class IEFrame
   StringReplace,thispage,thispage,% " - Microsoft Internet Explorer",,All
if thispage
{
   ControlGetText,URL,Edit1,% thispage . "ahk_class IEFrame"
parentWindow:=IE7_Get(thispage)
IE7_ExecuteJS(parentWindow, mouseover)
tname:=IE7_ExecuteJS(parentWindow, "","tname")
tindex:=IE7_ExecuteJS(parentWindow, "","tindex")
myLen:=IE7_ExecuteJS(parentWindow, "","myLen")
xx:=IE7_ExecuteJS(parentWindow, "","xx")
innerhtml:=IE7_ExecuteJS(parentWindow, "","innerhtml")
GuiControl,Text,Dom,% thispage . " `n" . URL . " `nDom accessable objects for document`.all collection `nElement type (" . tname . ")`nIndex (" . tindex . ")`nAttributes if any `n" . xx . "`nVisible text= " . innerhtml
com_release(parentWindow)
parentWindow=
}
return
^/::
SetTimer,dom,Off
Return
of course you need com and the ie7 functions
its pretty basic but on most pages it should give you detailed info about an html object and its atributes simply by rolling mouse over. including src of image
Never lose.
WIN or LEARN.

neXt
  • Members
  • 549 posts
  • Last active: May 20 2015 02:38 AM
  • Joined: 18 Mar 2007
I have a question about IE7_executeJS:
it has a third parameter "VarNames_to_Return" which isn't working out for me. As an example:
lets say document.form1.wo1.value = 555 i would like to retrieve this value.
i tried
COM_Init()

wh := IE7_Get("site.com")

js := "var text=document.form1.wo1.value"
IE7_ExecuteJS(wh, js, "text")
MSgBox %text%
but "text" returns as blank.

What am i missing here?

CannedCheese
  • Members
  • 120 posts
  • Last active: Sep 24 2014 04:31 PM
  • Joined: 21 May 2008
Do you get anything when you type...
javascript: var text=document.form1.wo1.value; alert(text);

in IE?

If your javascript code is correct, it should return the value. Problem is, when your javascript is incorrect, you don't get an error message.

neXt
  • Members
  • 549 posts
  • Last active: May 20 2015 02:38 AM
  • Joined: 18 Mar 2007
Yes, inside JS it works fine, "text" has a value and i'm running IE7. Any ideas?

CannedCheese
  • Members
  • 120 posts
  • Last active: Sep 24 2014 04:31 PM
  • Joined: 21 May 2008

COM_Init()

wh := IE7_Get("[color=red]<insert name of tab here - not site>[/color]")

js := "var text=document.form1.wo1.value"
IE7_ExecuteJS(wh, js, "text")
MSgBox %text%


here's an ugly but working example
Com_Init()
IE7_New("www.google.com")
myPageHandle := IE7_Get("Google")
sleep, 1000
msgbox,,,myPageHandle: %myPageHandle%, 1
x := IE7_ExecuteJS(myPageHandle, "var x=document.getElementById('gbar').childNodes[0].childNodes[4].innerText;", "x")
y := IE7_ExecuteJS(myPageHandle, "var x=document.getElementById('gbar').childNodes[0].childNodes[6].innerText;", "x")
z := IE7_ExecuteJS(myPageHandle, "var x=document.getElementById('gbar').childNodes[0].childNodes[8].innerText", "x")
msgbox,,, retrieved:`n%x%`n%y%`n%z%`nfrom www.google.com

let me know if this works

neXt
  • Members
  • 549 posts
  • Last active: May 20 2015 02:38 AM
  • Joined: 18 Mar 2007
Yes, this is working, but i don't get why your example works and mine doesn't:
COM_Init()
wh := IE7_Get("Google")
IE7_ExecuteJS(wh, "var x=document.f.q; x.value='this is a test'; var val=x.value; alert(val)", "val")
MsgBOx %val%
any ideas?

neXt
  • Members
  • 549 posts
  • Last active: May 20 2015 02:38 AM
  • Joined: 18 Mar 2007
ok, i get it now i had to do it like this:

val := IE7_ExecuteJS(wh, "var x=document.f.q; x.value='this is a test'; var val=x.value; alert(val)", "val")

Thanks!

CannedCheese
  • Members
  • 120 posts
  • Last active: Sep 24 2014 04:31 PM
  • Joined: 21 May 2008

Yes, this is working, but i don't get why your example works and mine doesn't:

COM_Init()
wh := IE7_Get("Google")
[color=red]val := [/color]IE7_ExecuteJS(wh, "var x=document.f.q; x.value='this is a test'; var val=x.value; alert(val)", "val")
MsgBOx %val%



CannedCheese
  • Members
  • 120 posts
  • Last active: Sep 24 2014 04:31 PM
  • Joined: 21 May 2008
See you got it on your own. Nice...

neXt
  • Members
  • 549 posts
  • Last active: May 20 2015 02:38 AM
  • Joined: 18 Mar 2007
CannedCheese, no, i got it thanks to your examples.

CannedCheese
  • Members
  • 120 posts
  • Last active: Sep 24 2014 04:31 PM
  • Joined: 21 May 2008

ok, i get it now i had to do it like this:

val := IE7_ExecuteJS(wh, "var x=document.f.q; x.value='this is a test'; var val=x.value; alert(val)", "val")

Thanks!


Can you please post your working code for your example? I can't get
IE7_ExecuteJS(wh, "var x=document.f.q; x.value='this is a test'; var val = x.value; alert(val)")

to do anything, even though it works fine when I plug it in the browser. With IE7_ExecuteJS, I can't get the alert to pop or the form to be filled.

neXt
  • Members
  • 549 posts
  • Last active: May 20 2015 02:38 AM
  • Joined: 18 Mar 2007
Hmm strange, this works fine for me:
SetTitleMatchMode 2
COM_Init()

IfWinNotExist Google
{
IE7_New("http://www.google.com/")
WinWait Google
}

wh := IE7_Get("Google")
IE7_ReadyState(wh)

js = 
(
var x = document.f.q;
x.value = 'this is a test';
var val = x.value;
alert('js popup: ' + val);
)

val := IE7_ExecuteJS(wh, js, "val")
MsgBox ahk popup: %val%


CannedCheese
  • Members
  • 120 posts
  • Last active: Sep 24 2014 04:31 PM
  • Joined: 21 May 2008
Ok, this works for me, though I'll need to look into why my code wasn't working. For those messing around with this example, if you chose to use IfWinExist to look for a google browser window, I highly recommend at least changing
IfWinExist Google
to
IfWinExist Google - Windows Internet

so that it isn't picking up incorrect windows like my GoogleTest.ahk or firefox google windows, etc. Probably better to use something like
myPageHandle := IE7_Get("Google")
if myPageHandle = 0
IE7_New("www.google.com")
...

or something like that.