how to get the position of fields

Virg g
  • Virg g
    Virg g

    I am doing only HTML parsing for locating the field elements with in a web page from form tag. I trying to find the complete path of a form element example Input Text fields from its Form tag. I am using ancestor function to get the complete path.  example ancestor function returns the path for input text field is

    "form table tr td input"

    But i want is positions of these elements  in the path with respect to its parent like

    "form table[1] tr[1] td[2] input".

    like first table from from and 1st tr from the table and 2nd td from tr so on..
    If it is not possible to get the complete path with positions atleast
    Is there any way to get the position of element without looping through all the elements of a node.

    Any help is hightly appreciated

    Thanks in advance


    • Arjan Somers
      Arjan Somers

      The w3c implementation of Node does not have a method to get a unique path.

      The simplest thing to do is probably to write your own getUniquePath() function as suggested on this site:

    • Virg g
      Virg g

      Thank you very much. It meets my requirement.