Sign in to follow this  
Followers 0
icu

IE: Links in Arrays [solved]

9 posts in this topic

#1 ·  Posted (edited)

Dear AutoIt Community,

Help please.

I'm trying to get AutoIt to perform certain functions with information displayed from a table in IE.

The table format will stay the same, it has 6 columns and 'n' number of rows (where n is the number of search results). Each row will have a link in Column 4 that I want AutoIt to click on.

So far I'ved tried:

_IEAction ($avTable_Array[1][4], "click")

_IELinkClickByText ($oIE, $avTable_Array[1][4], 0)

Upon reflection of the errors I was getting I've realised that the array co-ordinates are not automatically IE objects.

I then tried to create an object variable by using _IEGetObjByName ($oIE, $avTable_Array[1][4]) but this doesn't work.

How do I turn the content of an array co-ordinate into an object for the purpose of clicking it?

This is going to be a major problem for me because another array column cell will also need to be turned into an object as it contains a tick box that will need to be checked as my program completes a task using the information from the link.

When answering please assume I know nothing and if possible please comment any code snippets so I can follow what is happening.

Many thanks,

icu

Edited by icu

Share this post


Link to post
Share on other sites



hi icu,

Here is a quick snippet illustrating how to extract table data to arrays:

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

$oIE = _IE_Example("table")
$oTableCollection = _IETableGetCollection($oIE)
For $oEachTable In $oTableCollection
    $aTableData = _IETableWriteToArray($oEachTable, True)
    _ArrayDisplay($aTableData, $oEachTable.ID)
Next
_IEQuit($oIE)

Hope this gives you some ideas, :unsure:

-smartee

Share this post


Link to post
Share on other sites

Hi smartee,

Thanks for that code snippet, I'm up with the play in extracting IE tables into an array. Your code solution is a lot more elegant than what I ended up doing, which was counting all the tables from the $oIE page with _IETableGetCollection($oIE) (there were 8 tables) and then copying and pasting _IETableWriteToArray and _ArrayDisplay 8 times until I found the magic table that I wanted (table number 5), and then hard coded it into my code like so:

$nTable_Number = 5 ;search result table
$oTable = _IETableGetCollection ($oIE, $nTable_Number)
$avTable_Array = _IETableWriteToArray ($oTable, True)

A couple of things:

Q1: Why does "True" need to be stated in _IETableWriteToArray? The help file says nothing about this.

Q2: Doesn't "$oEachTable" in the line "For $oEachTable In $oTableCollection" need to be declared? I don't understand how the loop runs without having all of its variables declared. Any loop I try to code seems to have errors.

Anyways what I really need your help with is creating an object out of a link in a table. This has stopped my project in its tracks.

I've attached an annotated image file of the IE page and array data I'm struggling with.

So far I have gotten my AutoIt script to turn the table into an array but I can't seem to make IE objects out of the links and tick boxes in the array--so I have no way of getting AutoIt to click on them.

Q3: How do I get AutoIt to click on a particular link and a particular tick box?

Many thanks for your help,

icu

post-64643-0-71077600-1305410383_thumb.j

post-64643-0-45827400-1305410395_thumb.j

Share this post


Link to post
Share on other sites

hi again,

Ans1: You don't "need" true as the second parameter, that is a

Boolean value specifying whether to swap the rows and columns in the output array

Ans2: No, in AutoIt, variables needn't be declared before assigning values to them :unsure:. Don't believe me?

Ans3: Look at the IE* functions in the help-file, you may be especially interested in _IEFormElementCheckboxSelect(),_IEGetObjById() and _IELinkGetCollection().

Getting the text from the Javascript popup may be tricky, take a look at the page source and see how it obtains the text and see if you can directly access it.

This approach (processing row by row) may be less intimidating (than extracting all data at once) to do the whole lot:

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

$iRowCount = 0
$iCellCount = 0
$oIE = _IE_Example("table")
$oEachTable = _IETableGetCollection($oIE, 1)
For $oEachRow In $oEachTable.rows
    For $oEachCell In $oEachRow.cells
        ConsoleWrite("Table ID: " & $oEachTable.ID & ": Row#" & $iRowCount & " Col#" & $iCellCount & ":" & $oEachCell.innerHTML & @CRLF)
        ;if icellcount=2 do processing with $oEachCell.innerText
        ;if ..=4 get objects in this cell and click, or click link by cell inner text etc
        ;if ..=5 get objects in this cell, click checkbox
        $iCellCount += 1
    Next
    $iRowCount += 1
    $iCellCount = 0
Next
$iRowCount = 0
;done with table get submit button obj and click
_IEQuit($oIE)

Hope this gives you some kind of road-map, :>

Regards,

-smartee

Share this post


Link to post
Share on other sites

Thanks smartee!

Q1: Where is the documentation on ".row", ".ID" and ".innerHTML"? I didn't even know these things—-whatever they are--even existed. Searching the AutoIt Help file doesn't shed any light on them. Is there a list of these things somewhere?

Q2: Is your code suggestion a loop within a loop?

As I read it, your code loops through each row and for each cell writes a console line. I take it the "if" comments you've put are the hints I need to automate the process from those cells. I didn't even know you could write loops within loops... if that's what you're suggesting it's a very clever solution.

Thank you once again for your help!

Sincerely,

icu

Share this post


Link to post
Share on other sites

hi again, :unsure:

Ans1: Yes, there is comprehensive documentation on all HTML objects/properties/methods/collections across at MSDN: HTML and DHTML Reference.

Ans2: Indeed it is a nested loop. As it loops through the table row by row, it loops through the cells of each row.

Yup those are some little pointers to guide you in the correct direction. Glad I could help :>

Hope this clears up some things,

-smartee

Share this post


Link to post
Share on other sites

Hi smartee,

Thanks again for your quick reply. I'm not sure where to get the info on say ".row" from the MSDN website you gave me.

I thought AutoIt was its own language... and MSDN only covers certain supported languages like C++/C#/F# etc.?

How do those languages relate to AutoIt?

Share this post


Link to post
Share on other sites

hey :D

Here's that bit of info on the rows collection object ;)

Posted Image

I thought AutoIt was its own language... and MSDN only covers certain supported languages like C++/C#/F# etc.?

MSDN documented the COM object, while showing a couple examples of how to work with them in select languages. What these languages and AutoIt have in common is COM object support :unsure:

12th August, 2006 - v3.2.0

Added: COM object support.

In the IE.au3 library of UDF's authored by Dale Hohm, AutoIt interacts with the InternetExplorer COM Object to automate Windows Internet Explorer. Look at this snippet from IE.au3, pay attention to line 233:

Posted Image

In MS Visual Basic, here's how an InternetExplorer Object is created:

Set IE = CreateObject("InternetExplorer.Application")
Notice any similarities?

Although the programming language is different, we use the very same object. How? Through the use of COM, which essentially is a language-neutral way of implementing objects to allow their use/re-use in a multitude of different environments.

Hope this helps to clear things up :>

-smartee

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

smartee you are a legend... the whole cell count and row count stuff is brilliant! Thank you.

Sorry to keep bugging you but I've got a couple questions:

Q1: COM with AuotIt is fantastic, I had no idea. From what I gather COM isn't just in IE, I can use it with anything in Windows? All I need to do is look up the MSDN website you gave me and figure out the COM name of the 'sub-object' within an object variable and I can make it into an AuotIt object variable I can control?

So basically ".rows" is telling AutoIt to return all the COM objects ".rows" found in the previously declared table object "$oEachTable"?

Q2: I'm a bit confused with the syntax of the loop you've written and the 'human logic' behind it:

Does the line "For $oEachRow In $oEachTable.rows" tell AutoIt to create a variable "$oEachRow" with each of the rows in "$oEachTable.rows"? How does AutoIt know not to dump all the rows into that object? Because that's how I first 'read' that bit of code. After thinking about it I can see how "For $x In $y" could tell AutoIt "look at all the objects in $y and for each one temporarily put that current object into a newly created variable $x (starting with the first object). Run an operation until you get to a "Next" command, and then move to the next object in $y (putting the new object into $x), until you run out of objects in $y, and then carry on with the rest of the script.

Have I understood that correctly?

Thanks once again,

icu

Edited by icu

Share this post


Link to post
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
Sign in to follow this  
Followers 0