Jump to content
Sign in to follow this  
sammy1983

Array click

Recommended Posts

sammy1983

Hi,
 
Please look at the attached screenshot. When I search with UserID "122540", I get a list of users whose IDs are part of this search list, however, I ant to click on Username whose ID is "122540" and leave the rest. Hope I explained clearly.
 
Here is my code so far:

Local $sHTML = _IEDocReadHTML($oIE)
$array = StringRegExp($sHTML, '<(?i)td>\s*(.*?)\s*</(?i)td>', 3)
 
For $i = 0 To UBound($array) - 1
$User = $array[$i]
MsgBox(0, "", $User) ; Displays values of <td> tag
If $UserID = "122540" Then
<??????????> ; Need to know how to click on Username
EndIf
Next

Kindly help. Thanks.

Edited by sammy1983

Share this post


Link to post
Share on other sites
sammy1983

Hi,

 

Please look at the attached screenshot. When I search with UserID "122540", I get a list of users whose IDs are part of this search list, however, I ant to click on Username whose ID is "122540" and leave the rest. Hope I explained clearly.

 

Here is my code so far:

Local $sHTML = _IEDocReadHTML($oIE)
$array = StringRegExp($sHTML, '<(?i)td>\s*(.*?)\s*</(?i)td>', 3)
 
For $i = 0 To UBound($array) - 1
$User = $array[$i]
MsgBox(0, "", $User) ; Displays values of <td> tag
If $UserID = "122540" Then
<??????????> ; Need to know how to click on Username
EndIf
Next

Kindly help. Thanks.

post-80752-0-21577100-1394488847_thumb.j

Share this post


Link to post
Share on other sites
sammy1983

 

If you want to click the element, don't use stringregexp.  Instead, loop through

$oCol_td = _IETagNameGetCollection($oIE, "td")

 

Thanks jdelaney but if you look at the attachment, only Username has link which opens another page. So in this case, I have to match the UserID "122540" and click on "Kisha Craig". I know this can be achieved but somehow lost the path. Thanks for helping hand.

Share this post


Link to post
Share on other sites
jdelaney

when you found your td, you can use .parentnode to grab the row, and then grab the td with the name by using .childNodes[0]

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.

Share this post


Link to post
Share on other sites
sammy1983

when you found your td, you can use .parentnode to grab the row, and then grab the td with the name by using .item.

 

Honestly, I don't have a clue how to do this. This is the first time that I am encountering this problem. Can you show me how to write the code for this, if possible? Many thanks.

Share this post


Link to post
Share on other sites
sammy1983

Finally, I am able to match the Username and UserID using the below code.

Local $sHTML = _IEDocReadHTML($oIE)
    $array = StringRegExp($sHTML, '<(?i)td>\s*(.*?)\s*</(?i)td>', 3)

    Local $i = 0
    For $j = 1 To UBound($array) - 1
        $UserID = $array[$j]
        $Username = $array[$i]
        If $UserID = $sCellValue Then
            MsgBox(0, "", $Username)
            _IEAction($Username, "click")
        EndIf
        $i += 4
        $j += 3
    Next

However, now I wanna click on the Username which is hyperlinked. Can someone guide? I tried below but didn't work

_IEAction($Username, "click")

Kindly help.

Share this post


Link to post
Share on other sites
jdelaney

You are grabbing text, and expecting the text to correlate with the dom object.  That won't fly, ever.  I'll help you out, in a bit.


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.

Share this post


Link to post
Share on other sites
sammy1983

I am able to extract the Username using the below code:

Local $sHTML = _IEDocReadHTML($oIE)
    $array = StringRegExp($sHTML, '<(?i)td>\s*(.*?)\s*</(?i)td>', 3)
    Local $j = 0
    For $i = 1 To UBound($array) - 1
        $UserID = $array[$i]
        $Username = $array[$j]
        ConsoleWrite($Username)
        $j += 4
        $i += 3
    Next

The output on console is:

<a title="Customer Account Details" href="URL">Lawrence Wobker</a>

Now I don't know how to further break it and get just "Lawrence Wobker" so that I can use _IELinkClickByText($Username)?

Edited by sammy1983

Share this post


Link to post
Share on other sites
kylomas

sammy1983,

Have you tried this...?

Local $sHTML = _IEDocReadHTML($oIE)
_IELinkClickByText($oHTML, "122540")

Also, without your URL or an example of the HTML it is pretty hard to test anything.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
kylomas

Also, as jdelaney is suggesting, you should find your IE element and click on it using IE functions.  If you want to loop through links on a table then you can adapt this...

#include <IE.au3>
#include <array.au3>

_lnks(fileread('my.file'))

ConsoleWrite(@error & @LF)

Func _lnks($html_code)

    Local $o_htmlfile = ObjCreate('HTMLFILE')

    If Not IsObj($o_htmlfile) Then Return SetError(-1, 0, '')

    $o_htmlfile.open()
    $o_htmlfile.write($html_code)
    $o_htmlfile.close()

    Local $otbls = _IETagnameGetCollection($o_htmlfile, 'TABLE')

    if not isobj($otbls) then return seterror(-2)

    for $otbl in $otbls
        local $olnks = _ietagnamegetcollection($otbl, 'A')
        if not isobj($olnks) then return seterror(-3)
        ConsoleWrite('Links for table = ' & $otbl.id & ' ' & $otbl.title & ' ' & $otbl.summary & @LF)
        for $olnk in $olnks
            ConsoleWrite(@tab & $olnk.href & @LF)
        next
    next

EndFunc
Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
kylomas

This is a better example.  It takes a minute for the URL to load...

#include <IE.au3>
#include <array.au3>

local $oie = _IECreate('www.scoresandodds.com')

Local $otbls = _IETagnameGetCollection($oie, 'TABLE')

if not isobj($otbls) then ConsoleWrite('-1' & @LF)

for $otbl in $otbls
    local $olnks = _ietagnamegetcollection($otbl, 'A')
    if not isobj($olnks) then ConsoleWrite('-2' & @LF)
    ConsoleWrite('Links for table = ' & $otbl.id & ' ' & $otbl.title & ' ' & $otbl.summary & @LF)
    for $olnk in $olnks
        ConsoleWrite(@tab & $olnk.href & @LF)
    next
next

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
sammy1983

Problem solved. Finally found.

$Count = 22
    Local $sHTML = _IEDocReadHTML($oIE)
    $array = StringRegExp($sHTML, '<(?i)td>\s*(.*?)\s*</(?i)td>', 3)
    For $i = 1 To UBound($array) - 1
        $UserID = $array[$i]
            If $UserID = $sCellValue Then
                _IELinkClickByIndex($oIE, $Count)
                ExitLoop
            EndIf
        $i += 8
        $Count += 1
    Next

Thanks everyone.

Share this post


Link to post
Share on other sites
kylomas

sammy1983,

Glad you found something that works! 

Take note of this, however, any post-processing of HTML relies on the page not changing.  That is why we favor an _IE* based solution.
 


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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  

×