 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Carcophan
Joined: 24 Dec 2008 Posts: 1308 Location: :noitacoL
|
Posted: Fri Mar 19, 2010 8:11 pm Post subject: Can you get an elements index number from innertext? |
|
|
I am not sure exactly sure what I am trying to ask here, so I will explain it a little
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? |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Fri Mar 19, 2010 8:22 pm Post subject: |
|
|
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 . _________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5044 Location: the tunnel(?=light)
|
Posted: Fri Mar 19, 2010 8:48 pm Post subject: |
|
|
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 |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Fri Mar 19, 2010 9:17 pm Post subject: |
|
|
| 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
} |
_________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference
Last edited by jethrow on Mon Mar 22, 2010 8:08 pm; edited 1 time in total |
|
| Back to top |
|
 |
Carcophan
Joined: 24 Dec 2008 Posts: 1308 Location: :noitacoL
|
Posted: Mon Mar 22, 2010 5:20 pm Post subject: |
|
|
@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
|
|
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5044 Location: the tunnel(?=light)
|
|
| Back to top |
|
 |
Carcophan
Joined: 24 Dec 2008 Posts: 1308 Location: :noitacoL
|
Posted: Mon Mar 22, 2010 6:37 pm Post subject: |
|
|
| 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!  |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 3700 Location: Louisville KY USA
|
Posted: Mon Mar 22, 2010 7:26 pm Post subject: |
|
|
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
} |
_________________
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed; |
|
| Back to top |
|
 |
Carcophan
Joined: 24 Dec 2008 Posts: 1308 Location: :noitacoL
|
Posted: Mon Mar 22, 2010 8:56 pm Post subject: |
|
|
| 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!
@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 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|