Jump to content

HTML Table item/row click


Recommended Posts

Hi all

i am currently trying to click on an element in a HTML Table, but just can get it to work.

i am able to click the top of the table so it changes to sort  but just can't click on the element in the table.

an i need to click on element to continue in the site.

i have attached the code so far and pictures of the table  element want to click plus the source of the table.

i am able to get data in the table with $oTable = _IETableGetCollection($oIE, 2) but not able to click on them.

 

Help is very much appreciated

 

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

 AutoIt Version: 3.3.14.2
 Author:         myName

 Script Function:
    Template AutoIt script.

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

; Script Start - Add your code below here
#include <IE.au3>
#include "DOM.au3"
#include <Array.au3>
#include <MsgBoxConstants.au3>


Global $oIE = _IECreate("*")
_IELoadWait($oIE)
Sleep(2000)

_PageLogin($oIE)

_PageLoadWait()

_PageNewReq($oIE)

_PageLoadWait()

_InputModelInf($oIE)

_PageLoadWait()
Sleep(1000)

$aTableLink = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//table/tbody/tr/td[.='Name Of user']", 2000)
;~ $aTableLink = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//table/tbody/tr", 2000)
;~ _ArrayDisplay($aTableLink,"$aTableLink")
If IsArray($aTableLink) Then
    ConsoleWrite("Able to BGe_IEGetDOMObjByXPathWithAttributes($oIE, //table/tbody/tr/td[.='Name Of user'])" & @CRLF)
    For $i = 0 To UBound($aTableLink)-1
        ConsoleWrite("  OuterHTML : " & $aTableLink[$i].outerHTML & @CRLF)
        ConsoleWrite("  Parentnode :  " & $aTableLink[$i].parentnode & @CRLF)
        ConsoleWrite("  Parentnode.click :  " & $aTableLink[$i].parentnode.fireEvent("onclick","click") & @CRLF)
        $objClick = $aTableLink[$i].parentnode
;~      _IEAction($aTableLink[$i] , "focus")
        _IEAction($objClick , "focus")
;~      If _IEAction($aTableLink[$i], "click") Then
        If _IEAction($objClick, "click") Then
            ConsoleWrite("Able to _IEAction($aForumLink[0], 'click')" & @CRLF)
            _IELoadWait($oIE)
        Else
            ConsoleWrite("UNable to _IEAction($aForumLink[0], 'click')" & @CRLF)
            Exit 3
        EndIf

    Next
Else
    ConsoleWrite("Unable to BGe_IEGetDOMObjByXPathWithAttributes($oIE, //table/tbody/tr/td[.='Name Of user'])" & @CRLF)
    Exit 2
EndIf



_PageLoadWait()


Func _InputModelInf($oTmpIE) ; Add Var for Model & Serial in Func

    $oModelInput = _IEGetObjById($oTmpIE,"model")
    _IEAction($oModelInput,"focus")
    _IEDocInsertText($oModelInput, "*")

    $oSerialInput = _IEGetObjById($oTmpIE,"serial")
    _IEAction($oModelInput,"focus")
    _IEDocInsertText($oSerialInput, "*")

    $links = $oTmpIE.document.getElementsByClassName("btn btn-primary ng-scope")
    For $link In $links
        If $link.innertext =  "Søg" Or $link.innertext =  "Search" Then
            $link.click()
            ExitLoop
        EndIf
    Next

    Return True

EndFunc

Func _PageNewReq($oTmpIE)

    $links = $oTmpIE.document.getElementsByClassName("ng-scope k-link")
    For $link In $links
        If $link.innertext =  "Send ny fejlmelding" Or $link.innertext =  "Submit a New Service Request" Then
            $link.click()
            ExitLoop
        EndIf
    Next

    Return True

EndFunc

Func _PageLogin($oTmpIE)

    $oUserInput = _IEGetObjById($oTmpIE,"loginid")
    _IEDocInsertText($oUserInput, "*")

    $oPasswordInput = _IEGetObjById($oTmpIE,"password")
    _IEDocInsertText($oPasswordInput, "*")

    $links = $oTmpIE.document.getElementsByClassName("btn btn-primary login ng-scope")
    For $link In $links
        If $link.innertext =  "Sign in" Then
            $link.click()
            ExitLoop
        EndIf
    Next

    Return True

EndFunc

Func _PageLoadWait()
Local $PageLoadWait = False
;~ nav navbar-nav navbar-right ng-hide
;~ nav navbar-nav navbar-right

$tags = $oIE.document.GetElementsByTagName("ul")
For $tag in $tags
    $class_value = $tag.GetAttribute("class")
    If $class_value = "nav navbar-nav navbar-right" Then
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Webpage loading :) ' & @CRLF) ;### Debug Console
        $PageLoadWait = True
        ExitLoop
    EndIf
Next

Do
    sleep(250)
    For $tag in $tags
        $class_value = $tag.GetAttribute("class")
        If $class_value = "nav navbar-nav navbar-right ng-hide" Then
            ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Webpage load finished :)'& @CRLF) ;### Debug Console
            $PageLoadWait = False
            ExitLoop
        EndIf
    Next
Until $PageLoadWait = False


EndFunc

 

Thanks in advance

 

 

TablePicture.png

TableSource.png

Edited by islandspapand
Link to comment
Share on other sites

using my sig: $xpath = "//table/tbody/tr/td[.='some text to look for']"

Then with the return array, grab the parentnode and _ieaction click it.

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

Hi Jdelaney

Thanks for that had actually stumbeld upon your UDF while looking for a answer to my problem just could not get it to work first time around.

I have cleaned to code up a little and added your UDF, unfortunately i still can't get it to work.

Must likely just me that doens't understand it correctly, my skills/understanding in oIE are not great just what i can google myself and help file have gotten me so far :)

this is what i get when running the script:

Start Function=[BGe_IEGetDOMObjByXPathWithAttributes] with $sXPath=[//table/tbody/tr/td[.='Name of User']].
.='Name of User'
Start Function=[BGe_RecursiveGetObjWithAttributes] level=[0]: $sNodeName=[table], $bNodeIsRelative=[True] $bIsConstrainted=[False].
Start Function=[BGe_RecursiveGetObjWithAttributes] level=[1]: $sNodeName=[tbody], $bNodeIsRelative=[False] $bIsConstrainted=[False].
Start Function=[BGe_RecursiveGetObjWithAttributes] level=[2]: $sNodeName=[tr], $bNodeIsRelative=[False] $bIsConstrainted=[False].
Start Function=[BGe_RecursiveGetObjWithAttributes] level=[1]: $sNodeName=[tbody], $bNodeIsRelative=[False] $bIsConstrainted=[False].
Start Function=[BGe_RecursiveGetObjWithAttributes] level=[1]: $sNodeName=[tbody], $bNodeIsRelative=[False] $bIsConstrainted=[False].
Start Function=[BGe_RecursiveGetObjWithAttributes] level=[2]: $sNodeName=[tr], $bNodeIsRelative=[False] $bIsConstrainted=[False].
Start Function=[BGe_RecursiveGetObjWithAttributes] level=[3]: $sNodeName=[td], $bNodeIsRelative=[False] $bIsConstrainted=[True].
Start Function=[BGe_RecursiveGetObjWithAttributes] level=[3]: $sNodeName=[td], $bNodeIsRelative=[False] $bIsConstrainted=[True].
Start Function=[BGe_RecursiveGetObjWithAttributes] level=[3]: $sNodeName=[td], $bNodeIsRelative=[False] $bIsConstrainted=[True].
Start Function=[BGe_RecursiveGetObjWithAttributes] level=[3]: $sNodeName=[td], $bNodeIsRelative=[False] $bIsConstrainted=[True].
Start Function=[BGe_RecursiveGetObjWithAttributes] level=[3]: $sNodeName=[td], $bNodeIsRelative=[False] $bIsConstrainted=[True].
Start Function=[BGe_RecursiveGetObjWithAttributes] level=[3]: $sNodeName=[td], $bNodeIsRelative=[False] $bIsConstrainted=[True].
Start Function=[BGe_RecursiveGetObjWithAttributes] level=[3]: $sNodeName=[td], $bNodeIsRelative=[False] $bIsConstrainted=[True].
Start Function=[BGe_RecursiveGetObjWithAttributes] level=[3]: $sNodeName=[td], $bNodeIsRelative=[False] $bIsConstrainted=[True].
Start Function=[BGe_RecursiveGetObjWithAttributes] level=[3]: $sNodeName=[td], $bNodeIsRelative=[False] $bIsConstrainted=[True].
Able to BGe_IEGetDOMObjByXPathWithAttributes($oIE, //table/tbody/tr/td[.='IName of User])
  OuterHTML : <td role="gridcell">Name of User</td>
Able to _IEAction($aForumLink[0], 'click')

But the item is still not click, what am i doing wrong?

Link to comment
Share on other sites

  • 1 month later...

Okay so i have had some time to give it another try i just still can't get it to click.

So i find the obj find with the Xpath UDF, i am able to get all text, highlight the item, it just will not let me click.

Func _ClickTest()

$xpathForumLink = "//table/tbody/tr/td[.='Search item']"

$aForumLink = BGe_IEGetDOMObjByXPathWithAttributes($oIE,$xpathForumLink)
If IsArray($aForumLink) Then
;~     ConsoleWrite("Able to BGe_IEGetDOMObjByXPathWithAttributes($oIE, " & $xpathForumLink & ")" & @CRLF)
    ConsoleWrite("   " & $aForumLink[0].outerhtml & @CRLF)
    ConsoleWrite("   " & $aForumLink[0].parentElement.innerHTML & @CRLF)
    ConsoleWrite("   " & $aForumLink[0].parentElement.fireEvent("onclick") & @CRLF)
    ConsoleWrite("   " & $aForumLink[0].parentElement.fireEvent("onpointerdown") & @CRLF)
    ConsoleWrite("   " & $aForumLink[0].parentElement.fireEvent("onmousedown") & @CRLF)
Else
    ConsoleWrite("UNable to BGe_IEGetDOMObjByXPathWithAttributes($oIE, " & $xpathForumLink & ")" & @CRLF)
    Exit 2
EndIf


$oBjClick = $aForumLink[0].parentElement
_IEAction($oBjClick, "focus")
_IEAction($oBjClick, "click")


$oHighLight = $oIE.document.getSelection().selectAllChildren($aForumLink[0].parentNode) ; Higlight item

ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aForumLink[0].parentNode.innerHTML = ' & $aForumLink[0].parentNode.innerHTML & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aForumLink[0].parentNode.parentNode.innerHTML = ' & $aForumLink[0].parentNode.parentNode.innerHTML & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aForumLink[0].parentNode.parentNode.innerHTML = ' & $aForumLink[0].parentNode.parentNode.focus() & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aForumLink[0].parentNode.parentNode.innerHTML = ' & $aForumLink[0].parentNode.parentNode.fireEvent("onclick") & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aForumLink[0].parentNode.parentNode.innerHTML = ' & $aForumLink[0].parentNode.parentNode.fireEvent("onclick","click") & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aForumLink[0].parentNode.parentNode.innerHTML = ' & $aForumLink[0].parentNode.parentNode.fireEvent("onmousedown") & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aForumLink[0].parentNode.parentNode.innerHTML = ' & $aForumLink[0].parentNode.parentNode.fireEvent("onmousedown","mousedown") & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aForumLink[0].parentNode.parentNode.innerHTML = ' & $aForumLink[0].parentNode.parentNode.fireEvent("onpointerdown") & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aForumLink[0].parentNode.parentNode.innerHTML = ' & $aForumLink[0].parentNode.parentNode.fireEvent("onpointerdown","pointerdown") & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$oBjClick = $aForumLink[0].parentNode
_IEAction($oBjClick, "focus")
_IEAction($oBjClick, "click")

$oElement = $oIE.document.selection.createRange().parentElement()
ConsoleWrite($oElement.nodename & @CRLF)
$oElement.fireEvent("onclick","click")
$oElement.fireEvent("onmousedown","mousedown")
$oElement.fireEvent("onmouseup","mouseup")
$oElement.fireEvent("onselect","select")
$oElement.fireEvent("onpointerdown","pointerdown")
$sReturn = "NodeName=[" & $oElement.nodename & "] NodeText=[" & $oElement.innertext & "]" & @CRLF & @CRLF
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sReturn = ' & $sReturn & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

;events in <table class="k-selectable" role="grid" style="-ms-touch-action: double-tap-zoom pinch-zoom;" data-role="selectable">
;~ click
;~ mousedown
;~ pointerdown

EndFunc

 

Edited by islandspapand
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

×
×
  • Create New...