There is a Firefox extension, WebDeveloper. It has one menu item, outline current element. It shows position of element. Example:
"html > body #id-479 > center > table > tbody > tr > td .main_content > form > table > tbody > tr > td > ul[0]" 
for an element in this page.
Firstly, please note that that is not a unique position. If you want to be able to find what was selected/clicked later, you need to use an XPath-like notation; something like:

"html > body#id-479 > center[0] > table[0] > tbody [0] > tr[1] > td.main_content > form[0] > table[0] > tbody[0] > tr[0] > td[0] > ul"

Secondly, roughly the same question was asked by user2000 recently in Position on Web Page. The conclusions are:

And that's just the content-targeting part. The remainder is communicating the "path" string to your perl back-end via AJAX (XMLHttpRequest, etc).

Update:

I see that like YourMother, I assumed you'd want to remember the XPath-like position in order to translate it to a (browser-relative) pixel-position.

If that's not the case, then you can start with something like YourMother has written below (using jquery, or some other library that smooths over browser differences).

To be accurate, you will need to form an XPath-like expression, so why not use real XPath?

There's a cross-platform library available here.

To construct the XPath expression, you'll have to walk up the DOM from the target element to the document.body (root). At each level, you'll need to determine 'id', 'class' and sibling-rank (with that selection priority).

-David


In reply to Re: Webpage Element Information by erroneousBollock
in thread Webpage Element Information by artist

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.