Jump to content
Sign in to follow this  
islandspapand

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

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

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

    • By wysocki
      I have a smartphone and I use it to access my email. However, when composing an email on it I have a problem. My list of phone contacts on the phone is very different from my list of email contacts in my Thunderbird desktop app.  I use my Gmail address book to store primarily phone contacts, and I use Thunderbird for my list of email contacts. I wanted a way to get my Thunderbird contact list onto my smartphone to be able to compose emails to addresses in that list. Here's my solution.
      I wrote a script to export my Thunderbird Personal Address Book to a csv file. It then reads that file and re-writes it with html wrappers around the data to make it into a nicely formatted web page. It then uploads the htm file to my website. On my smartphone, I created a shortcut to the file's URL and whenever I click it, I get the list displayed. Each contact shows name and email address along with a COPY button that will put the address into the clipboard. Then in my email client, I can easily paste that address into it. Alternatively, clicking on the actual email link will open a new message dialog in your email client with that address already entered.
      To use the app, all you need to do is use Thunderbird and have a webserver available. You'll need to download the FTPEX.AU3 file from this website and make a few changes to some constants around line 17 for FTP login info, etc.
       
      pab2ftp.au3
    • By SkysLastChance
      What would be the best way to grab the last digits of this <span>? One of the problems I know I am going to have is sometimes it will be 1 digit other times it might be 3. 

      I am trying to get the list of spans and I get this error.

       
      $oInputs = _IETagNameGetCollection($oIE, "span") $sTxt = "" For $oInput In $oInputs     $sTxt &= $oInput.Innertext & @CRLF Next MsgBox($MB_SYSTEMMODAL, "Form Input Type", "Form: " & $oInput.form.name & @CRLF & @CRLF & "         Types :" & @CRLF & $sTxt)  
    • By nacerbaaziz
      good morning all.
      first lit me give you all a thinks to your help
      you're help me allot thank you all.
      sirs today i've a new problem
      it's not a problem but thing i want to add it to blind accessability.
      the ListBox can send a notification when the user send a double click on it items
      but as we know that the blind users can't use the mouse for that they use the keybord to navigate.
      as we know that the enter replace the double click on the keybord
      for that i need when the user send a inter above any listBox item the list send a double click notification.
      i know some of you tell me that i can use the  GUISetAccelerators function
      but the enter has a other tasks such as leav a blanc line on edits and activate the defaultButton and other tasks.
      that what i need and i hope that you can help me
      this is a simple example.
      #include <GUIConstantsEx.au3> #include <StructureConstants.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <ListBoxConstants.au3> Example() Func Example() Local $sMESSAGE = "The following buttons have been clicked" GUICreate("My GUI list") ; will create a dialog box that when displayed is centered Local $idButton_Add = GUICtrlCreateButton("Add", 64, 32, 75, 25) Local $idButton_Clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25) global $idMylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 121, 97) GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling GUICtrlSetData(-1, $sMESSAGE) global $DummyList = GUICtrlCreateDummy() GUICtrlSendToDummy($DummyList, 1) Local $idButton_Close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25) GUIRegisterMsg($WM_command, "WM_command") GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton_Add GUICtrlSetData($idMylist, "You clicked button No1|") Case $idButton_Clear GUICtrlSetData($idMylist, "") Case $idButton_Close MsgBox($MB_SYSTEMMODAL, "", "the closing button has been clicked", 2) Exit case $DummyList $g_iTemp = GUICtrlRead($DummyList) if $g_iTemp = $LBN_DBLCLK then ;$LBN_DBLCLK then msgBox(64, "", "") endIf GUICtrlSendToDummy($DummyList, 0) EndSwitch WEnd EndFunc ;==>Example Func WM_command($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = $lParam $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case GUICtrlGetHandle($idMylist) Switch $iCode Case $LBN_SELCHANGE, $LBN_DBLCLK, $LBN_SELCANCEL, $LBN_SETFOCUS GUICtrlSendToDummy($DummyList, $iCode) case else ;GUICtrlSendToDummy($DummyTreeview, 1) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc  
    • By _leo_
      Hey there!
      I am having a problem with clicking a button in IE. As you can see in the code, there would be a class name to click it, but since this button exists several times with exactly the same code, I can only use the "Noch nicht veröffentlicht" to separate it from the others. But this part is just pure text without any classification. 
      "<div class="checkmark" data-v-1e5b1f70=""><svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 16 16" data-v-1e5b1f70=""><circle cx="8" cy="8" r="8" data-v-1e5b1f70="" /></svg></div>Noch nicht veröffentlicht"
      I was trying to click it with:
      #include <IE.au3> local $oNNVs = _IEFormGetCollection($oIE2) For $oNNV in $oNNVs If String($oNNV.innertext) = "Noch nicht veröffentlicht" Then _IEAction($oNNV, "click") EndIf Next and:
      $inputs = $oIE2.document.getElementsByTagName("div") For $input In $inputs If $input.innertext == "Noch nicht veröffentlicht" then $input.click() EndIf Next But nothing seems to work. Thanks for the help!
    • By matwachich
      Hi guys!
      A pretty simple UDF to convert HTML to PDF using wkHTMLtoPDF.
      It uses the C API of the tool (DLL), so no external process, no ActiveX or COM sh*t.
      See the example, and the documentation of wkHTMLtoPDF.
      Cheers
      https://github.com/matwachich/wkhtmltopdf-au3
×
×
  • Create New...