Jump to content
Sign in to follow this  
islandspapand

HTML Table item/row click

Recommended Posts

islandspapand

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

Share this post


Link to post
Share on other sites
jdelaney

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.

Share this post


Link to post
Share on other sites
islandspapand

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?

Share this post


Link to post
Share on other sites
islandspapand

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

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  

  • Similar Content

    • nooneclose
      By nooneclose
      Hello again, I am in phase two of my help bot. I cannot figure out how to properly code Autoit to click on a webpage button using the I.E UDF. I want to click on the button that I have attached as an image. This button does not have a name but it has an ID. Here is the HTML code for this button that I found using chromes developer inspector.
      HTML Code: 
      <img role="button" tabindex="-1" id="toolactions_INSERT-tbb_image" src="nav_icon_insertkey.gif" alt="New Work Order CTRL+ALT+I" draggable="false"> Here is the code that I have so far:
      ;******************************************************************************* ; Opens IE and fill out a New Workorder ;******************************************************************************* ; Start IE at the ** Tracking Application in ****** $oIE = _IECreate("https:I_am_Bound_by_my_company_to_not_reveal_this_webpage") ; Wait for a browser page load to complete _IELoadWait($oIE) Sleep(6000) ; Store the field names where the important data will be sent Local $nWorkOrderB = _IEGetObjById($oIE, "toolactions_INSERT-tbb_image") _IEAction($nWorkOrderB, "click")  I want my program to click on the button that looks like a piece of paper with a blue # 
      (For those wondering, I am allowed to send images just not the URL.) 
      As always any help would be appreciated. 

    • lavascript
      By lavascript
      I have a Word document containing a 9-column table where row 1 is the column headers. My goal is to read the table into a 2d array, remove some rows, update some fields, and add a few rows to the end. The resulting array will likely be a different length. Next, I want to write the data back into the table. If it's easier, I can write the data to a new document from a template containing the same table header with a blank 2nd row.
      Here's my early attempt:
      Local $oWord = _Word_Create() Local $oDoc = _Word_DocOpen($oWord, $sFile) Local $aData = _Word_DocTableRead($oDoc, 1) $aData[3][5] = "Something else" Local $oRange = _Word_DocRangeSet($oDoc, 0) $oRange = _Word_DocRangeSet($oDoc, $oRange, $wdCell, 9) _Word_DocTableWrite($oRange,$aData) This, unfortunately, writes the entire array into the first cell of row 2. What am I doing wrong?
       
    • ur
      By ur
      Is there any UDF to remove all anchor tags <a> with a particular class (and also its sub elements completely) in a html document.
      Here the classes are browse and breadcrumbs
      Like in the below image.


       
      I am not able to find that option in IE.au3
       
      Please suggest.
    • milkmoron
      By milkmoron
      I am trying to automate something in a web browser but i need some help with finding the html code to a web applet. How do I access the code.
    • Seminko
      By Seminko
      Is there a way to grab non-hardcoded but rather javascript generated data from a webpage?
      Tried a get request as well as _IEBodyReadHTML but both seem to grab the code without the javascript generated data.
      $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", "link", False) $oHTTP.Send() $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status Global $DataArray[10][5] If $oStatusCode <> 200 Then Exit MsgBox(1, "Error", "Status Code <> 200") EndIf FileWrite(@ScriptDir & "\output.txt", $oReceived) ; //////// #include <IE.au3> Local $FullLink = "link" Local $oIE = _IECreate($FullLink, 0, 0) _IELoadWait($oIE) Local $sText = _IEBodyReadHTML($oIE) FileWrite(@ScriptDir & "\output.txt", $sText)  
×