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

    • SkysLastChance
      By SkysLastChance
       
      WinActivate("MEDITECH - Internet Explorer") Sleep (500) $oIE = _IEAttach("MEDITECH") $oDiv1 = _IEGetObjById($oIE, "sysmenu-searchbarbutton") _IEAction($oDiv1, "click") I am just trying to click the little magnifying glass, next to the gear button with no luck. I was hoping someone might have an idea why this is not working?
       

    • Burgs
      By Burgs
      Hello,
        I have a website with a Google Map I setup using the Google Map API.  It works and displays just fine.  However to make it useful to me I need to be able to dynamically change the map to display different areas by sending new Latitude and Longitude coordinates.  I am having difficulty making this happen.  Here is my code thus far:
      #include <IE.au3> $oIE3 = _IECreate("http://my_sample_website.html") ;just an example, not an actual site... _IELoadWait($oIE3) $s_word = "lat:" $oInputs = _IETagNameAllGetCollection($oIE3) if @error <> 0 Then MsgBox($MB_SYSTEMMODAL, "ERROR", "Error is: " & @error) EndIf ;@error For $oInput In $oInputs if Number($iPos) == -1 Then $iPos = StringInStr($oInput.innerHTML, String($s_word)) if (Number($iPos) > 0) AND (@error == 0) Then ConsoleWrite("I FOUND IT...! " & String($s_word) & @CRLF) $sHTML = _IEBodyReadHTML($oIE3) $_lat_look = 0 $_lng_look = 0 $_end_look = 0 ;default $_lat_look = StringInStr(String($sHTML), "lat:") if Number($_lat_look) <> 0 Then $_lng_look = StringInStr(String($sHTML), "lng:") if Number($_lng_look) <> 0 Then $_end_look = StringInStr(String($sHTML), "}") if Number($_end_look) <> 0 Then ConsoleWrite("HTML BODY: " & $sHTML & @CRLF) $_old_lat = String(StringMid(String($sHTML), $_lat_look, ($_lng_look - $_lat_look))) $_old_lng = String(StringMid(String($sHTML), $_lng_look, ($_end_look - $_lng_look))) ConsoleWrite("$_old_lat: " & $_old_lat & @CRLF) ConsoleWrite("$_old_lng: " & $_old_lng & @CRLF) $_new_lat = "lat: " & String("-34.397") & ", " $_new_lng = "lng: " & String("150.644") & "}; " ConsoleWrite("...new lat is: " & String($_new_lat) & " new lng is: " & String($_new_lng) & @CRLF) $_LOOK = StringReplace($_old_lat, 1, String($_new_lat)) $_LOOK2 = StringReplace($_old_lng, 1, String($_new_lng)) ConsoleWrite("$_LOOK: " & $_LOOK & "$_LOOK2: " & $_LOOK2 & @CRLF) EndIf ;'$_end_look' NOT "0"... $iPos = -1 EndIf ;'String($s_word)' was found in the collection '$oInputs' EndIf ;'$iPos' is "-1" Next  
        I am having trouble trying to replace the line in the HTML ($sHTML variable in my example) that contains the "lat:" and "lng:" information.  I figure if I can replace that line everything else remains the same, and in theory, the map should cycle to display a map with the new latitude and longitude coordinates...I hope. 
        I have attempted to write the $sHTML to a text document and then use '_IEBodyWriteHTML' to read it back into the webpage HTML however that is not working.  There must be an easier method to accomplish this...what am I missing here...?  Any thoughts greatly appreciated.  Regards.       
    • dadalt
      By dadalt
      Hi!
      I have a button where I need to close it!
      I was doing through  clicking same position in screen but there are some id's that have different sizes.
      What are the possible ways to click this closable button?
      Is there a way to close it through id? Is there a way to get it's position through it's ID?  
      Thanks in advance!


    • Ascer
      By Ascer
      1. Description.
      Udf working with MSDN System.Collections.ArrayList. Allow you to make fast operations on huge arrays, speed is even x10 better than basic _ArrayAdd.  Not prefered for small arrays < 600 items. 2. Requirements
      .NET Framework 1.1 - 4.5 (on this version Microsoft destroy old rules) System Windows 3. Possibilities.
      ;=============================================================================================================== ; UDF Name: List.au3 ; ; Date: 2018-02-17, 10:52 ; Description: Simple udf to create System Collections as ArrayList and make multiple actions on them. ; ; Function(s): _ListCreate -> Creates a new list ; _ListCapacity -> Gets a list size in bytes ; _ListCount -> Gets items count in list ; _ListIsFixedSize -> Get bool if list if fixed size ; _ListIsReadOnly -> Get bool if list is read only ; _ListIsSynchronized -> Get bool if list is synchronized ; _ListGetItem -> Get item on index ; _ListSetItem -> Set item on index ; ; _ListAdd -> Add item at end of list ; _ListClear -> Remove all list items ; _ListClone -> Duplicate list in new var ; _ListContains -> Get bool if item is in list ; _ListGetHashCode -> Get hash code for list ; _ListGetRange -> Get list with items between indexs ; _ListIndexOf -> Get index of item ; _ListInsert -> Insert a new item on index ; _ListInsertRange -> Insert list into list on index ; _ListLastIndexOf -> Get index last of item ; _ListRemove -> Remove first found item ; _ListRemoveAt -> Remove item in index ; _ListRemoveRange -> Remove items between indexs ; _ListReverse -> Reverse all items in list ; _ListSetRange -> Set new value for items in range ; _ListSort -> Sort items in list (speed of reading) ; _ListToString -> Get list object name ; _ListTrimToSize -> Remove unused space in list ; ; Author(s): Ascer ;=============================================================================================================== 4. Downloads
      List.au3 5. Examples
      SpeedTest _ArrayAdd vs ListAdd SpeedTest ArraySearch vs ListIndexOf Basic usage - crating guild with members  
    • Robdog1955
      By Robdog1955
      I'm trying to click a button on a web page. I have added a couple of MsgBox lines to allow me to watch what happens on the page. As you can see the first half of my script enters data into text boxes on the page. I have no problem there. I just cannot click on the region buttons. The "set focus" line causes an outline to appear around the EU button and the "click button" line causes the "Pick a Region" text to disappear. Here is the code I have so far.
      #include <IE.au3> Local $oIE = _IECreate("http://questchecker.com/") Local $iQuestID = "123456" Local $sCharacterName = "CharacterName" Local $colForms = _IEFormGetCollection($oIE) $iCount = 0 For $oForm In $colForms $oFormElements = _IEFormElementGetCollection($oForm) For $oFormElement In $oFormElements $iCount = $iCount + 1 Local $sTagName = StringLower($oFormElement.tagName) Local $sElementType = $oFormElement.type Local $sElementName = $oFormElement.name Switch $iCount Case 6 _IEFormElementSetValue($oFormElement, "MyRealm", 0) ; realm Case 7 _IEFormElementSetValue($oFormElement, $sCharacterName, 0) Case 8 _IEFormElementSetValue($oFormElement, $iQuestID, 0) EndSwitch Next Next Local $oButtons = _IEGetObjByName($oIE, "questForm") For $oButton In $oButtons If _IEFormElementGetValue($oButton) = "US" Then MsgBox(0, "", "Click Okay to set focus") _IEAction($oButton, "focus") MsgBox(0, "", "Click Okay to click button") _IEAction($oButton, "click") ExitLoop EndIf Next MsgBox(0, "", "Click Okay to quit") _IEQuit($oIE) Exit  
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.