Sign in to follow this  
Followers 0
islandspapand

HTML Table item/row click

3 posts in this topic

#1 ·  Posted (edited)

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

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  
Followers 0

  • Similar Content

    • Gowrisankar
      By Gowrisankar
      Hello everyone,
      I'm trying to pass values to elements in a website.
      The elements are present within a table, which is again present within a table, which is inside a form.
      I tried to read the form, tables, etc., but with no results. It appears to me that the elements, tables, form, etc., were not read at all.
      The following is what I tried. Please guide me.
      ;I tried the following to read the tables into arrays #include <IE.au3> #include <MsgBoxConstants.au3> Local $oIE = _IECreate() _IENavigate($oIE, "---- URL HERE ----") _IELoadWait($oIE) $o_Table = _IETableGetCollection ($oIE) $i_NumTables = @extended For $i = 0 To $i_NumTables - 1 Step 1 $o_Table_Temp2 = _IETableGetCollection ($oIE, $i) $a_TableData = _IETableWriteToArray ($o_Table_Temp2) _ArrayDisplay($a_TableData) Next  
      ;I tried the following code to pass value to the field #include <IE.au3> #include <MsgBoxConstants.au3> Local $oIE = _IECreate() _IENavigate($oIE, "---- URL HERE ----", 0) _IELoadWait($oIE) Local $oForm = _IEFormGetObjByName($oIE, "default") Local $oField = _IEFormElementGetObjByName($oForm, "tGroup") _IEFormElementSetValue($oField, "---- VALUE HERE ----")  
      The following is the html view of the website and the highlighted field is the one that I want to pass values to. Since this is an official website, I can't share the exact url.

    • Spask
      By Spask
      Hi, I'm trying to find a text value inside of a html.
      This is what the line looks like normally:
      <p id="line1" class> <span class="bot">TEXT HERE</span> </p> The text then changes to a non breaking space:
      <p id="line1" class> <span class="bot">&nbsp;</span> </p> And then it changes back to normal text but it's different every time.
      Can I code this so that it grabs the text every time it changes and has a variable that represents it?
      I currently have this inside of my loop:
      $span = .document.getElementsByTagName("span") For $text In $span If $text.value = "&nbsp;" Then Sleep(50) MsgBox(0,0,0) ;messagebox to test if it can be found, but I don't know how to grab the text EndIf Next The problem is that there are many other lines in the html that have the same span but are called "line3", "line5", etc and the one I need is from "line1".
      I will appreciate if anyone can help with this!
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      Before all, I want to say that I'm doing this script to see how _IE* functions work, and see if my studs can hack a quiz I'm working on.
      I want to clarify that I'm not automating any game, bypassing any CAPTCHAs, or anything that could damage anyone.
      I was trying to autofill a form, based on which question is displayed.
      The question is always stored in here:
      <header> <h1><span class="questionid">1. </span>Here goes the question</h1> </header> And answers are stored in here:
      <ul class="answers"> <li><label><span><input id="answer_0" name="answer[]" type="radio" value="0">Answer 1</span></label></li> <li><label><span><input id="answer_1" name="answer[]" type="radio" value="1">Answer 2</span></label></li> <li><label><span><input id="answer_2" name="answer[]" type="radio" value="2">Anwser 3</span></label></li> <li><label><span><input id="answer_3" name="answer[]" type="radio" value="3">Answer 4</span></label></li> </ul></fieldset></form></div> And, there are 15 questions like this.
      How can automatically fill my form?
      Thanks in advance
      Francesco
    • houser747
      By houser747
      I have previously used _IEFormElementGetObjByName and _IEFormElementSetValue to enter text into a search box on a form and then submit the form.
      I am now trying to enter text into a search box which is not part of a form. 
      Here is the HTML from the website that i'm trying to enter the data on and then submit the search.
      <div class="row">
          <div class="form-group col-xs-12">
              <span id="FullWidthWithSubmenuContent_FullWidthContent_MainContent_AircraftRegistry_lblSearchText" for="input-search">Registreringsbeteckning</span>
              <div class="input-group col-xs-12">
                  <span id="FullWidthWithSubmenuContent_FullWidthContent_MainContent_AircraftRegistry_preSearchText" class="input-group-addon">SE -</span>
                  <input name="ctl00$FullWidthWithSubmenuContent$FullWidthContent$MainContent$AircraftRegistry$txtSearchText" type="text" value="DTH" id="FullWidthWithSubmenuContent_FullWidthContent_MainContent_AircraftRegistry_txtSearchText" class="form-control" />
              </div>
          </div>
      </div>
      <div class="row">
          <div class="form-group col-xs-12">
              <label class="sr-only" for="">Sök</label>
              <input type="submit" name="ctl00$FullWidthWithSubmenuContent$FullWidthContent$MainContent$AircraftRegistry$btnSearch" value="Sök" id="FullWidthWithSubmenuContent_FullWidthContent_MainContent_AircraftRegistry_btnSearch" class="btn btn-primary ladda-button" data-style="expand-right" />
          </div>
      </div>
      Many thanks in advance
      cheers
      Roger
    • OtenMoten
      By OtenMoten
      Hello dear community,
       
      definitely I need external help now. I've did all 'ControlClick() - Tutorials' and read a lot of topics about interaction betweend AutoIT and external programs.
      The most of them are about "Clicking a button ...". In my case it's different because I need to click a specific element within the program.
       
      The 'program' what I am talking about is called Mendeley. It's library software for documents administration.
       
      In the attachements in picture '1.jpg' you can see the red marked Help element. 
      In the picture '2.jpg' you see the context menu of the Help element. This is what I'm trying to do with the ControlClick() function.
       
      Following I represent my code which not worked for me:
      #include <MsgBoxConstants.au3> Opt("WinTitleMatchMode", 2) $hWnd = WinGetHandle("Mendeley Desktop", "") MsgBox($MB_SYSTEMMODAL, "handle check", $hWnd) ControlClick($hWnd, "Mendeley Desktop", "Help") The MsgBox tells me the number of the handle of the Mendeley window. It's not 0 so for me it means the window is recognized correctly.
       
      When I'm execute the script the Help element is not clicked.
      Any suggestions for me?
       
      Kind regards
      OtenMoten