Sign in to follow this  
Followers 0
nbala75

Selecting Radio button in IE based on text present

18 posts in this topic

#1 ·  Posted (edited)

Posted Image

I just need to select the radio button on the left side based on some criteria on that Row.

For eg: If there are multiple rows, i want to select particular row's radio button where 'Scrip' matches "abc" and 'Qty' matches "20"

plz suggest where to look into

Edited by nbala75

Share this post


Link to post
Share on other sites



I suppose it depends on how that page is structured. Have you checked out the help file yet? Look under Used Defined Functions Reference, under IE Management. Those are all the IE functions. You could possibly use _IETableWriteToArray to write that table to an array and find what you need in the array, then go back and click the correct radio. Or...you could use _IEBodyReadHTML or _IEBodyReadText to read the entire page and parse it to find what you need. I think it will really depends on how that page is built.

The software you are using, what is it called? Do you have the source code for the page? That might help get you more specific answers...

Also, if you can, try to find and download DebugBar for IE, it really helps at least if you're new to IE COM.

Good luck!

Share this post


Link to post
Share on other sites

In particular, you can walk the <TR> tags (table rows) in a loop, looking for your search value inside the appropriate <TD> tags (table data cells).

This method uses the array from _IETableWriteToArray():

#include <IE.au3>

$oIE = _IE_Example("table")
$oTable = _IETableGetCollection($oIE, 0)
$aTableData = _IETableWriteToArray($oTable, False) ; Note table is [col][row]

; Find column for "great"
$iCol = -1
For $c = 0 To UBound($aTableData, 2) - 1
    If String($aTableData[$c][0]) = "great" Then
        $iCol = $c
        ExitLoop
    EndIf
Next
If $iCol = -1 Then
    MsgBox(16, "Error", "Column not found")
    Exit
EndIf

; Find row for "dog" in that column
$iRow = -1
For $r = 1 To UBound($aTableData) - 1
    If String($aTableData[$iCol][$r]) = "dog" Then
        $iRow = $r
        ExitLoop
    EndIf
Next
If $iRow = -1 Then
    MsgBox(16, "Error", "Row not found")
    Exit
EndIf

; Get value from col 5 of that row
$oTR = _IETagNameGetCollection($oTable, "TR", $iRow) ; reference to TR tag
$oTD = _IETagNameGetCollection($oTR, "TD", 5) ; reference to TD tag
$sVal = _IEPropertyGet($oTD, "innerText")
MsgBox(64, "Result", "Col 5 of the row where the 'great' col = 'dog' is:  " & $sVal)

This one avoids that and just works directly with the DOM:

#include <IE.au3>

$oIE = _IE_Example("table")
$oTable = _IETableGetCollection($oIE, 0) ; First table

; Find column for "great"
$sVal = ""
$iTD = -1
$oTR = _IETagNameGetCollection($oTable, "TR", 0) ; First row (headers)
$colTDs = _IETagNameGetCollection($oTR, "TD")
For $oTD In $colTDs
    If String($oTD.innerText) = "great" Then
        $iTD = $oTD.cellIndex ; Found column, save index
        ExitLoop
    EndIf
Next
If $iTD = -1 Then
    MsgBox(16, "Error", "Column not found")
    Exit
EndIf

$colTRs = _IETagNameGetCollection($oTable, "TR", -1) ; Collection of all rows
For $oTR In $colTRs
    ; Read search column
    $oTD = _IETagNameGetCollection($oTR, "TD", $iTD)
    If String($oTD.innerText) = "dog" Then
        ; Found search string, read col 5 of same row
        $oTD = _IETagNameGetCollection($oTR, "TD", 5)
        $sVal = $oTD.innerText
        ExitLoop
    EndIf
Next
If $sVal = "" Then
    MsgBox(16, "Error", "Column not found")
    Exit
EndIf

MsgBox(64, "Result", "Col 5 of the row where the 'great' col = 'dog' is:  " & $sVal)

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Mr Mitchell

Thanx for ur kind words

As u have guessed correctly, iam not a full time programmer..i mostly copy paste stuff from example files and write my own beginner level programs.

As suggested, i will look into those IE functions

Btw how do we know the source code of a particular IE page?

Thanx again

Share this post


Link to post
Share on other sites

Thanx a lot for ur help Mr PsaltyDS

I think i need to work a lot to understand what u have just given

Let me give a try

Thanx again for ur time

Share this post


Link to post
Share on other sites

Automating a web page involves learning the Document Object Model (DOM), which is what the _IE* functions in the IE.au3 UDF work with. The page source (click View|Source in IE) is just some text that tells the browser to create Objects in memory. When the browser sees a <table> tag, it creates a table object in memory, then the nested <tr> tags create rows in the table, and within each set of <tr> tags there are <td> tags for the data cells, all created as objects in memory by the browser.

Sometimes you can parse the source text and determine what you want, but not always. It depends on how complicated the page is. The source for the very simple example page used above looks like this:

<HTML>
<HEAD>
<TITLE>_IE_Example('table')</TITLE>
<STYLE>body {font-family: Arial}</STYLE>
</HEAD>
<BODY>
$oTableOne = _IETableGetObjByName($oIE, &quot;tableOne&quot;)<br>
&lt;table border=1 id='tableOne'&gt;<p>
<table border=1 id='tableOne'>
    <tr>
        <td>AutoIt</td>
        <td>is</td>
        <td>really</td>
        <td>great</td>
        <td>with</td>
        <td>IE.au3</td>
    </tr>
    <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
        <td>4</td>
        <td>5</td>
        <td>6</td>
    </tr>
    <tr>
        <td>the</td>
        <td>quick</td>
        <td>red</td>
        <td>fox</td>
        <td>jumped</td>
        <td>over</td>
    </tr>
    <tr>
        <td>the</td>
        <td>lazy</td>
        <td>brown</td>
        <td>dog</td>
        <td>the</td>
        <td>time</td>
    </tr>
    <tr>
        <td>has</td>
        <td>come</td>
        <td>for</td>
        <td>all</td>
        <td>good</td>
        <td>men</td>
    </tr>
    <tr>
        <td>to</td>
        <td>come</td>
        <td>to</td>
        <td>the</td>
        <td>aid</td>
        <td>of</td>
    </tr>
</table>
<p>
$oTableTwo = _IETableGetObjByName($oIE, &quot;tableTwo&quot;)<br>
&lt;table border=&quot;1&quot; id='tableTwo'&gt;<p>
<table border=1 id='tableTwo'>
    <tr>
        <td colspan='4'>Table Top</td>
    </tr>
    <tr>
        <td>One</td>
        <td colspan='3'>Two</td>
    </tr>
    <tr>
        <td>Three</td>
        <td>Four</td>
        <td colspan='2'>Five</td>
    </tr>
    <tr>
        <td>Six</td>
        <td colspan='3'>Seven</td>
    </tr>
    <tr>
        <td>Eight</td>
        <td>Nine</td>
        <td>Ten</td>
        <td>Eleven</td>
    </tr>
</table>
</BODY>
</HTML>

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hello

I was just trying to understand how a simple login to hotmail account using autoit functions work

So i used the example script given in the Autoit help file

When i tried using it, there were couple of errors thrown in...

Can someone plz let me know what iam missing?

Iam stuck in the very first class ;)

Posted Image

Edited by nbala75

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Is there really a <form> named "f1" on that page? Because the error says it didn't find it. The rest of the errors were all caused by that first one.

;)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

thank u for reply

Plz have a look at the attached image...wherein i cud see the Form with its name "f1" in Hotmail login page...and also i have not changed anything in the script. It is just a copy paste from help file

What else cud be the issue here??

plz help

Posted Image

Share this post


Link to post
Share on other sites

can someone plz help me on this??

thanx

thank u for reply

Plz have a look at the attached image...wherein i cud see the Form with its name "f1" in Hotmail login page...and also i have not changed anything in the script. It is just a copy paste from help file

What else cud be the issue here??

plz help

Posted Image

Share this post


Link to post
Share on other sites

I opened www.hotmail.com and checked the source. I dont see a form called "f1". Are you sure you are inspecting the right source ?

Share this post


Link to post
Share on other sites

I opened www.hotmail.com and checked the source. I dont see a form called "f1". Are you sure you are inspecting the right source ?

thanx for trying from ur end

that is precisely why i attached the screenshot of the Hotmail page with Debugbar

iam new to debugbar. plz click on my image and see whether "form f1" has been correctly identified by me or not in the debugbar pane

thanx again

Share this post


Link to post
Share on other sites

Try this code:

$oIE = _IECreate("www.hotmail.com")
    $oForms = _IEFormGetCollection ($oIE)
    For $oForm In $oForms
        MsgBox(0, "Form Info", $oForm.name)
    Next

yes, as per ur suggestion, it does show "f1" as a lone form name in that website

what else to be done?? :graduated:

Share this post


Link to post
Share on other sites

$oIE = _IECreate("www.hotmail.com")

$oForms = _IEFormGetCollection ($oIE)

For $oForm In $oForms

$o_form = $oForm

Next

And then continue from $o_login

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

$oIE = _IECreate("www.hotmail.com")

$oForms = _IEFormGetCollection ($oIE)

For $oForm In $oForms

$o_form = $oForm

Next

And then continue from $o_login

Hurray....it works :( but why now?

why it wasnt working earlier??

there is only one form by name "f1"...why it works only when the form name is fetched this way?? :graduated:

thanx again to u

Edited by nbala75

Share this post


Link to post
Share on other sites

thank u mr.Juvigy

finally i cud login to my trading account. That account had a radio button to select just before login. I cud manage to select the correct radio button and then login correctly. I used _IEFormElementRadioSelect.

Coming back to my very first question for which this thread was opened by me. I wish i cud select the correct radio button on the screen shot given in my first post of this thread. I cud not work on that today since the website is not fully functional today. Neverthless my question is how to select a particular radio button when values are dynamic, ie, as and when orders are placed, an entry with a radio button is shown to the user on the screen.

I mean, that there may be numerous orders at a time, some may be in the process of execution or some may be cancelled. If some orders are executed or cancelled, on Refreshing the screen, they will not find a place in the screen. So we tend to get new orders every second and some others are getting thrown out of the screen. Each new order/entry will be having a radio button.

Right now when i login into my trading site, while using _IEFormElementRadioSelect, i took the value of that particular radio button and used it. That value seemed to be constant.

In a dynamic scenario, as explained above, how to select a particular radio button, when we do not know the value of that particular radio button?

I feel the question may be big, but, the answer may be tiny

Thanx again for helping a lay man

Share this post


Link to post
Share on other sites

Maybe use _IETagNameGetCollection to get all radio's on the page ( it maybe only one )

And then use a loop to (if more then only one) to identify somehow the correct radio.

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