Jump to content

Click link in a table


Recommended Posts

Hi I'm trying to click on a table link for the below

 

Is this the correct way to do it 

 

image.thumb.png.a4b46b21134471de69037a878ccb489c.png

So I used this For loop to lop through and click Query

_IELoadWait($oIE)

;Search Td tags for query
ConsoleWrite(@CRLF & "Starting for loop for TDs to find a payment with Query.")
$Tds = _IETagNameGetCollection($oIE, "td")
Sleep(4000)
If IsObj($Tds) Then
    For $Td In $Tds
        If $Td.getAttribute("value") = "Query" Then
            MsgBox(64, ' TD Found', 'TD found with value: ' & $Td.getAttribute("value"), 2)
            _IEAction($Td, 'click')
            ConsoleWrite(@CRLF & "Clicking Table item")
            ExitLoop
        EndIf
    Next
EndIf

However my output on Console is so it's not hitting the table. as it doesn't use the ConsoleWrite bit on "Clicking Table Item" 

Starting for loop for TDs to find a payment with Query.>Exit code: 0    Time: 31.86

 

Link to comment
Share on other sites

Also I'm able to click by ID 

ConsoleWrite(@CRLF & "Clicking using ID")
$TableID= _IEGetObjById($oIE, "ctl00_MPH_ctlPaymentFileLineListing_PaymentFileLineListItem566917_ctlHyperLink")
_IEAction($TableID, "click")

So I'm wondering if there is a way to return the ID of the table by searching the table for Query which I can then use for an IE_Action click 

Link to comment
Share on other sites

Thanks I gave that a try with textcontent and innertext but still not hitting the ConsoleWrite line

If IsObj($Tds) Then
    For $Td In $Tds
        If $Td.getAttribute("textcontent") = "Query" Then
            MsgBox(64, ' TD Found', 'TD found with value: ' & $Td.getAttribute("value"), 2)
            _IEAction($Td, 'click')
            ConsoleWrite(@CRLF & "Clicking Table item")
            ExitLoop
        EndIf
    Next
EndIf

 

Link to comment
Share on other sites

I tried ensuring the case matched

 

Quote
;Search Td tags for query
ConsoleWrite(@CRLF & "Starting for loop for TDs to find a payment with Query.")
$Tds = _IETagNameGetCollection($oIE, "td")
Sleep(4000)
If IsObj($Tds) Then
   ConsoleWrite(@CRLF & "$Tds is a Obj")
    For $Td In $Tds
        If $Td.getAttribute("innerText") = "Query" Then
            MsgBox(64, ' TD Found', 'TD found with value: ' & $Td.getAttribute("innerText"), 2)
            _IEAction($Td, 'click')
            ConsoleWrite(@CRLF & "Clicking Table item")
            ExitLoop
        EndIf
    Next
EndIf

ConsoleWrite(@CRLF & "Testing loop via links")
$colLinks = _IELinkGetCollection($oIE)
For $oLink in $colLinks
    If String($oLink.textContent) = "Query" Then
       ConsoleWrite(@CRLF & "Found query")
       _IEAction($oLink, "click")
        ExitLoop
    EndIf
Next

 

However I got the following on console output 

Starting for loop for TDs to find a payment with Query.
$Tds is a Obj
Testing loop via links>Exit code: 0

 

Link to comment
Share on other sites

In fact I managed to get the following console output using 

ConsoleWrite(@CRLF & "Testing loop via links")
$colLinks = _IETagNameGetCollection($oIE, "td")
For $oLink in $colLinks
    If String($oLink.textContent) = "Query" Then
       ConsoleWrite(@CRLF & "Found query")
       _IEAction($oLink, "click")
        ExitLoop
    EndIf
Next

Testing loop via links
Found query>Exit code: 0    Time: 43.13

 

However I suspect it is finding the first mention of query 

 

Is it possible to search only a table using the table class or table id? 

Link to comment
Share on other sites

5 minutes ago, Danp2 said:

Have you tried logging each found TD's contents to the Scite console? That way you can get a handle on why your current code isn't working as expected.

Thanks I tried this on a unique phrase and it clicked the link correctly

 

My problem is I want to click an item in the table that is a query but query is mentioned in a few other tables. Is it possible to only search a table by class or ID rather than a full collection? 

Link to comment
Share on other sites

4 minutes ago, CaptainBeardsEyesBeard said:

Is it possible to only search a table by class or ID rather than a full collection? 

Yes. Instead of passing $oIE to _IETagNameGetCollection, you can pass a reference to another element. For example --

$oLink = _IEGetObjById($oIE, "ctl00_MPH_ctlPaymentFileLineListing_PaymentFileLineListItem566917_ctlHyperLink")
$oTDs = _IETagNameGetCollection($oLink, "td")

 

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...