Jump to content

@extended Clarification


Recommended Posts

Hey All!

I guess maybe I don't understand how @extended saves to a variable.

I have a script that's checking for the number of tables on a webpage and getting the second to last one with the below snippet.

When I include the msgbox the $count variable is recognized from the subtraction from $iNumtables.  When I exclude though, it pulls the last table everytime like my $count variable isn't being recognized until I actually use it in the msgbox.

Sorry I'm a bit new to understanding how that works.  Is there any way to ensure my $count gets saved so that I don't have to put the msgbox for it to work properly?

Thanks!

$oTable = _IETableGetCollection($oIE)
Local $iNumTables = @extended
$count = $iNumTables - 1
;MsgBox("", "", $count)
$oTable = _IETableGetCollection($oIE, $count)
$aTableData = _IETableWriteToArray($oTable, True)
_ArrayDisplay($aTableData)
;_ArrayDisplay($tablearray)
Link to comment
Share on other sites

Hi dar100111

are you trying to read all the tables in the page from the last to the second (except the first)?

you could do like this:

$oTable = _IETableGetCollection($oIE)
If Not @error Then
    Local $iNumTables = @extended ; number of tables on the page
    If $iNumTables > 1 Then ; if more than 1 tables (you do not want the first)

        Local $count = $iNumTables ; start from the last table

        Do
            $oTable = _IETableGetCollection($oIE, $count)
            $aTableData = _IETableWriteToArray($oTable, True)
            _ArrayDisplay($aTableData)
            $count -= 1 ; decrease $count by 1
        Until $count = 1 ; finish if we are pointing to the first table

    EndIf
EndIf

what's wrong with @extended ?

Edit:

added error checking as rightly suggested in post # 3

Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Noticed pinco put a line to check this, but if _IETableGetCollection() fails, @extended returns the invalid parameter number instead of a count. Being finicky as it is, it's a good idea to check any output from _IE functions to ensure it's not erroring and it's seeing the correct data.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Hey Guys.  In my case most of the times it's been 7 tables in the page that I'm looking on but can vary.  @extended is working correctly showing "7" when I put the msgbox in there it's showing the correct amount and I'm able to pull the table right before the last one every time; as long as my msgbox is in there.   Here's the whole code.  It seems to be working flawlessly and then I take out the Msgbox and it no longer pulls the table I want.  I was using the msgbox just to check and make sure it was working which it has been showing the tables accurately.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.1
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <IE.au3>
#include <Excel.au3>
#include <Array.au3>

;$file = _ExcelBookOpen(@ScriptDir&"\Miner Workbook.xlsx")
;$filearray = _ExcelReadSheetToArray($file)
;_ArrayDisplay($filearray)
$oIE = _IECreate("http://intranet.chq.ei/enet/main", 0, 1)
Sleep(2000)
$input = _IEGetObjByName($oIE, "expoquery")
$button = _IEGetObjByName($oIE, "searchexpo")
$searchimg = _IEImgGetCollection($oIE, 5)
_IEAction($searchimg, "click")
_IELoadWait($oIE)
;cs start after getting to tracking
$ref = _IEGetObjByName($oIE, "reference")
$bbutton = _IEGetObjByName($oIE, "sqSimplePromptSubmit")
_IEFormElementSetValue($ref, "H180028113")
_IEAction($bbutton, "click")
_IELoadWait($oIE)
;tagcount($oIE)

Local $iNumTables = @extended
$count = $iNumTables - 1
MsgBox("", "", $count)
$oTable = _IETableGetCollection($oIE, $count)
$aTableData = _IETableWriteToArray($oTable, True)
_ArrayDisplay($aTableData)



Func tagcount($oIE)
$counter = 0
Local $oElements = _IETagNameAllGetCollection($oIE)
For $oElement In $oElements
    $counter = $counter + 1
    MsgBox(0, "Element Info", "Tagname: " &$oElement.tagname &@lf&"Instance: "&$counter&@lf&"innerText: " & $oElement.innerText&@lf&"ID: "&$oElement.id)
Next
EndFunc
Edited by dar100111
Link to comment
Share on other sites

What value are you expecting @extended to have?  I'd suggest this, if you want the second to last table:

$oTableCol = _IETableGetCollection($oIE)
$count = $oTableCol.length - 1

$oTable = _IETableGetCollection($oIE, $count)
$aTableData = _IETableWriteToArray($oTable, True)
_ArrayDisplay($aTableData)

 

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

dar100111

in your last listing is missing "$oTable = _IETableGetCollection($oIE)"? anyway,
maybe the delay of the msgbox gives times to IE to load the table, you could insert something like this to wait untill the table collection is ready:

do
$oTable = _IETableGetCollection($oIE)
Until IsObj($oTable)

Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Hey Jdelaney,

I tried your code example, even adding a sleep in; just in case.  Same Error.  Returns 7 just like the other code using @extended and shows it in my msgbox.  When I comment off the msgbox and run with your example, I get the same results.  I am baffled.  Trying to figure out the relationship of why taking out this msgbox causes this issue.

Sleep(2000)
$oTable = _IETableGetCollection($oIE)
$tabcount = $oTable.length - 1
;MsgBox("", "", $tabcount)
$oTable = _IETableGetCollection($oIE, $tabcount)
$aTableData = _IETableWriteToArray($oTable, True)
_ArrayDisplay($aTableData)
Link to comment
Share on other sites

Hey Pin,

Put your Do statement in just to make sure.  Same results.

do
 $oTable = _IETableGetCollection($oIE)
 Until IsObj($oTable)
;$oTable = _IETableGetCollection($oIE)
$tabcount = $oTable.length - 1
MsgBox("", "", $tabcount)
$oTable = _IETableGetCollection($oIE, $tabcount)
$aTableData = _IETableWriteToArray($oTable, True)
_ArrayDisplay($aTableData)
Link to comment
Share on other sites

dar100111

in your last listing is missing "$oTable = _IETableGetCollection($oIE)"? anyway,

maybe the delay of the msgbox gives times to IE to load the table, you could insert something like this to wait untill the table collection is ready:

do

$oTable = _IETableGetCollection($oIE)

Until IsObj($oTable)

 

Or

do
  Sleep(10)
Until Not _IEPropertyGet($oIE, "busy")
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

try this:

do
 $oTable = _IETableGetCollection($oIE)
 Until IsObj($oTable)
;$oTable = _IETableGetCollection($oIE)
$tabcount = $oTable.length - 1
; MsgBox("", "", $tabcount)
do
$oTable = _IETableGetCollection($oIE, $tabcount)
 Until IsObj($oTable)

$aTableData = _IETableWriteToArray($oTable, True)
_ArrayDisplay($aTableData)

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Do me a favor and initialize all of your variables before using them.

Then test again.

Edited by Mechaflash
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Local $oTable = _IETableGetCollection($oIE, 7). 

I just added a Sleep after the IsObj check and it's the only way I've been able to get it to work, even hardcoding 7 in function.

do
 Local $oTable = _IETableGetCollection($oIE)
 Until IsObj($oTable)

I have _ieloadwait and Do until IsObj and still have to include the Sleep it looks like.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.1
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <IE.au3>
#include <Excel.au3>
#include <Array.au3>

;$file = _ExcelBookOpen(@ScriptDir&"\Miner Workbook.xlsx")
;$filearray = _ExcelReadSheetToArray($file)
;_ArrayDisplay($filearray)
Local $oIE = _IECreate("http://intranet.chq.ei/enet/main", 0, 1)
Sleep(2000)
Local $input = _IEGetObjByName($oIE, "expoquery")
Local $button = _IEGetObjByName($oIE, "searchexpo")
Local $searchimg = _IEImgGetCollection($oIE, 5)
_IEAction($searchimg, "click")
_IELoadWait($oIE)
;cs start after getting to tracking

Local $ref = _IEGetObjByName($oIE, "reference")
Local $bbutton = _IEGetObjByName($oIE, "sqSimplePromptSubmit")
_IEFormElementSetValue($ref, "H180028113")
_IEAction($bbutton, "click")
_IELoadWait($oIE)

;tagcount($oIE)
;try to find onclick radio button for full event view
;$elements = _IETagNameAllGetCollection($oIE, "isCoreEvent")


do
 Local $oTable = _IETableGetCollection($oIE)
 Until IsObj($oTable)
;$oTable = _IETableGetCollection($oIE)

Local $check = 7
Local $tabcount = $oTable.length - 1
;MsgBox("", "", $tabcount)

Sleep(1000)
do
Local $oTable = _IETableGetCollection($oIE, $tabcount)
 Until IsObj($oTable)

Local $aTableData = _IETableWriteToArray($oTable, True)
_ArrayDisplay($aTableData)
Link to comment
Share on other sites

It makes absolutely no sense that it works in the way you've presented it. If everything before your Sleep() is working and you haven't navigated away or interacted with the page to make it load other information, everything after Sleep() should work without the Sleep(). Are you cutting out some code in between that we're not seeing?

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Hey Mecha.  I'm with you, and no that's the entire script.  The only thing that I can think of is that the table counts are being pulled properly but the query on the site isn't compiling the results yet.  I've been beating my head on this and definitely don't want to rely on the sleep.  I might call it to pull the table over and over until the array is greater than one row or build some logic in there so that I know I'm getting what I need.

Link to comment
Share on other sites

Post the table html (don't worry about the rows...just the <TABLE>, and possibly it's parent|grandparent elements).  You can probably get the object in a better fashion than instance based.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

That's what I'm wondering too... try this.. 

Do
  Sleep(10)
Until Not _IEPropertyGet($oIE, "busy")

 

Put that in right after the _IELoadWait()

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...