AutoHotkey Community

It is currently May 27th, 2012, 3:03 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: March 19th, 2010, 9:11 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
I am not sure exactly sure what I am trying to ask here, so I will explain it a little :x


I have been using ComGetVal(x) and element index numbers for a while, it works great with static content.

I have been stuggeling with pulling some dynamic content on a webpage though. The page in question has 3 sections (pass/fail/notes) that vary in size. Sometimes they are blank, sometimes they can each contain several items each.

Each item in the pass/fail/notes section, adds to the 'index' count for all elements past the pass/fail/notes section. The data I want to pull is located after the dynamic p/f/n stuff.


After testing like 100 accounts, I found that the index number for word 'notes' will always be 10 less than index number for the data that I want to pull.



So what I guess I am trying to ask is:
If I only have the Elements value/innerText information, which just reads 'notes', how can i get its index number?

((Using iWeb build 2.5, the "name" and "ID" fields are always blank, only the "Index" and "Value/InnerText" will ever contain data))

The index number for 'Notes' will always be dynamic... but the index value I WANT should always be +10 from 'notes'.

Thoughts?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 9:22 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
I don't think you can directly. However, you could loop through all the elements on the page until you find matching data ( perhaps even matching innerHTML ). It might be slightly quicker to do this within the webpage itself, save the identified index to a variable, and extract that variable from the webpage. Or, you could check and see how iWeb_clickText/clickValue works. Just some thoughts :wink: .

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 9:48 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
I think there must be a better way of getting the data but the long road would be this (using the current thread):

Code:
iWeb_Init()
pwb:=iWeb_getWin("Can you get an elements index number from innertext?")
Loop {
  COM_Error(0)
  if t := COM_Invoke(pwb,"document.all[" A_Index-1 "].innerText") {
    if (t == "Carcophan") {
      i := COM_Invoke(pwb,"document.all[" A_Index-1 "].sourceIndex")
      break
    }
  }
}
MsgBox % COM_Invoke(pwb,"document.all[" i "].innerText")
COM_Error(1)
iWeb_Release(pwb)
iWeb_Term()
return

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 10:17 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
I wrote:
It might be slightly quicker to do this within the webpage ...
Here's an example of what I meant ( using AHKL & COM_L ):
Code:
innerText := "Carcophan"
jscript =
(
a=document.all;
for( i=0; i<=a.length; i++ )
   if( a[i].innerText == '
%innerText%' )
      break;
if ( i > a.length )
   i = 'N/A'

)
   
pWin := IEGet().document.parentWindow
pWin.execScript( jscript )
MsgBox, % pWin.i


IEGet(Name="") {
   IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
   Name := Name="New Tab" ? "about:Tabs":RegExReplace(Name," - (Windows|Microsoft) Internet Explorer")
   Windows := COM_CreateObject( "Shell.Application" ).Windows, COM_Error( False )
   Loop, % Windows.Count
      If ( pwb:=Windows.item[A_Index-1] ).LocationName=Name && InStr( pwb.FullName, "iexplore.exe" ) {
         COM_Error( True )
         Return pwb
      }
}


OR, here's a standard AHK & COM version:
Code:
innerText := "Carcophan"
jscript =
(
a=document.all;
for( i=0; i<=a.length; i++ )
   if( a[i].innerText == '
%innerText%' )
      break;
if ( i > a.length )
   i = 'N/A'
)

COM_Init()
pwb := IEGet()
pWin := COM_Invoke( pwb, "document.parentWindow" )
COM_Invoke( pWin, "execScript", jscript )
MsgBox, % COM_Invoke( pWin, "i" )
COM_Release( pwb ), COM_Release( pWin ), COM_Term()

IEGet( name="" )
{
   IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame ; Get active window if no parameter
   Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs" : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
   oShell := COM_CreateObject( "Shell.Application" ) ; Contains reference to all explorer windows
   Loop, % COM_Invoke( oShell, "Windows.Count" ) {   
      If pwb := COM_Invoke( oShell, "Windows.item[" A_Index-1 "]" )
         If ( COM_Invoke( pwb, "LocationName" ) = name && InStr( COM_Invoke( pwb, "FullName" ), "iexplore.exe" ) )
            Break
      COM_Release( pwb ), pwb := ""
   }
   COM_Release( oShell )
   Return, pwb
}

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Last edited by jethrow on March 22nd, 2010, 9:08 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2010, 6:20 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
@Sinkfaze:
I was working with your sample, but keep running into an error non-existant function error for some reason.

Using your example:
Code:

;error message=
;Call to nonexistent function 
;Specifically: iWeb_Release(pwb)

;I have tried using libraries: com/iweb/invokedeep/iweb_com


iWeb_Init()
pwb:=iWeb_getWin("WebsiteNameHere")
Loop
{
  COM_Error(0)
 
  if t := COM_Invoke(pwb,"document.all[" A_Index-1 "].innerText")
  {
    if (t == "Notes")
   {
      i := COM_Invoke(pwb,"document.all[" A_Index-1 "].sourceIndex")
      break
    }
  }
}


MsgBox % COM_Invoke(pwb,"document.all[" i "].innerText")

COM_Error(1)
iWeb_Release(pwb)
iWeb_Term()
return



@Jethrow:
I like the look of the AHK_L script you posted, but sadly working with AHK_L at this time is out of the picture. IT will not let us start using a variation of AHK at this time, it is 'AHK or nothing'. (Reason unknown)





I was looking into iWeb_getDomObj, and tried to make a few test scripts, but haven't gotten anything working yet for that. I started with info from http://www.autohotkey.com/forum/topic55277.html , and am still digging around for more bits.



Code:
;dream code, that I would like to eventually accomplish
;trying to find the best work around for this psudo-code example



If(value/innerText = 'notes')
    then, get index_value associated with value/innerText for 'notes'

index_value += 10   ;since desired var is +10 from notes

msgbox, value/innerText for the new +10 index_value numer



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2010, 6:24 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
iWeb_Release() should be in the latest version of the iWeb library, you may want to re-download it.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2010, 7:37 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
sinkfaze wrote:
iWeb_Release() should be in the latest version of the iWeb library, you may want to re-download it.
Huzzah :!: :!: Sorry for being out of date.

Code:

iWeb_Init()
pwb:=iWeb_getWin("Agilyst - Microsoft Internet Explorer")
Loop
{
  COM_Error(0)
 
  if t := COM_Invoke(pwb,"document.all[" A_Index-1 "].innerText")
  {
    if (t == "Comments")
   {
      i := COM_Invoke(pwb,"document.all[" A_Index-1 "].sourceIndex")
     ii := COM_Invoke(pwb,"document.all[" A_Index+10 "].sourceIndex")
      break
    }
  }
}


MsgBox % COM_Invoke(pwb,"document.all[" i "].innerText")
MsgBox % COM_Invoke(pwb,"document.all[" ii "].innerText")

COM_Error(1)
iWeb_Release(pwb)
iWeb_Term()
return


Msgbox2 shows the value that I wished to obtain. I still have to test for errors but overall it looks like it is working! :shock:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2010, 8:26 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
i tried some time ago to get Sinkfaze to post this as his own so i wouldnt have to support it ever but oh well

Code:
COM_CoInitialize()
MsgBox   %   IE_Find("notes","page title","innertext",10)
COM_CoUninitialize()
IE_Find(needle,win="A",property="",offset=0)
{
   If   (win=="A")
      WinGetTitle,win,%win% ahk_class IEFrame
   StringSplit,wins,win,-
   _autotrim:=A_AutoTrim
   AutoTrim,On   
   wins1=%wins1%
   AutoTrim,%_autotrim%
   If   psh   :=   COM_CreateObject("Shell.Application") {
      If   psw   :=   COM_Invoke(psh,   "Windows") {
         Loop, %   COM_Invoke(psw,   "Count")
            If   pwb   :=   (InStr(COM_Invoke(psw,"Item[" A_Index-1 "].LocationName"),wins1)   && InStr(COM_Invoke(psw,"Item[" A_Index-1 "].FullName"), "iexplore.exe")) ? COM_Invoke(psw,"Item", A_Index-1) :
               Break
         COM_Release(psw)
      }
      COM_Release(psh)
   }
   If   !pwb
      Return
   If   !pWin:=COM_QueryService(pwb,   "{332C4427-26CB-11D0-B483-00C04FD90119}",   "{332C4427-26CB-11D0-B483-00C04FD90119}")
   {
      COM_Release(pwb)
      Return
   }   
   If   oRange:=COM_Invoke(pWin,"document.body.createTextRange")
   {
      COM_Invoke(oRange,"findText",needle)
      _res:=property ? COM_Invoke(pWin,"Document.all.item[" COM_Invoke(oRange,"parentElement.sourceIndex")+offset "]." property) :  COM_Invoke(pWin,"Document.all.item", COM_Invoke(oRange,"parentElement.sourceIndex")+offset)
      COM_Release(oRange)
   }   
   COM_Release(pWin)
   COM_Release(pwb)
   Return   _res
}

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2010, 9:56 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
tank wrote:
i tried some time ago to get Sinkfaze to post this as his own so i wouldnt have to support it ever but oh well

Just admit it, you love the pain! :twisted:


@Jethrow;
Thanks for the updated post with the non-AHK_L example.




Sidenote:
13 months after starting with this particular webpage/portal... and we are now finally able to interact with it without using the mouse and x/y coords. Makes me wish that I didnt put it off for so long


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], rbrtryn, Yahoo [Bot] and 29 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group