Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^5: WWW::Mechanize - how to get the position of an element on my screen?

by Corion (Pope)
on Jan 31, 2012 at 21:19 UTC ( #951071=note: print w/ replies, xml ) Need Help??


in reply to Re^4: WWW::Mechanize - how to get the position of an element on my screen?
in thread WWW::Mechanize - how to get the position of an element on my screen?

That's not how things work. Most likely, whatever Javascript or HTML rendering tool you use will also support XPath or CSS selectors. Use these tools instead.


Comment on Re^5: WWW::Mechanize - how to get the position of an element on my screen?
Re^6: WWW::Mechanize - how to get the position of an element on my screen?
by mascip (Pilgrim) on Feb 01, 2012 at 00:05 UTC

    Thank you for this precious advice.
    I see two ways out of this:

    1. i start this mini-project all over again (it's very doable : at the moment i'm only doing tests to identify the tools i should use), using XPath instead of HTML::Tree. Which will allow me to use this ->element_coordinate() function from WWW::Mechanize::Firefox.

    2. i have found HTML::TreeBuilder::XPath which apparently enables to use both Trees and XPath. Could this enable me to use ->element_coordinates() from my tree nodes ?

    I'm trying solution 2. I've been fighting to get this to work, and finally got to a point where i identified my obstacle :
    Apparently, get_element_coordinate() takes a MozRepl::RemoteObject::Instance as an argument, and i didn't find how HTML::Tree::XPath could return me such an object from my HTML::Element tree node.

    If someone had a simple solution to this, great.
    Otherwize, i'll just start it again with XPAth. Which would be good for me to learn anyway.
    As you can see, i'm learning as i go, and there's lots i have to learn. Any book / tutorial / website for me to learn would be very welcome. I like book-learning more than all. As an indication, i read "Perl & LWP" and "Spidering Hacks" already. But neither of them addresses the DOM (i'm not even sure what it is), nor Javascript (i did two tutorials, but it's not enough), nor XPath in depth, nor... all the important things i forget.

    Thanks a lot for building this very useful library Corion, and for answering beginners' questions : it's very kind of you.
    Have a good day =o)

      WWW::Mechanize::Firefox only works with Firefox. There is no way to make HTML::TreeBuilder::XPath objects work with it.

      Again, if you want element positions, you need Javascript. HTML::Tree / TreeBuilder don't do Javascript (or other HTML layout). WWW::Mechanize::Firefox does XPath and Javascript. It has other drawbacks, like needing a display.

        This morning I realized how stupid that was : i'm creating my Tree from the HTML content only, while the object position can be influenced by the Javascript (And other stuff? And something that manages the display layout i guess), which WWW::Mechanize::Firefox "takes into account" (simple words for beginner understanding).

        I read it several times, i knew it but forgot it while doing this first test. I guess i hoped there could be a (bijective) correspondence between the two. And i made this mistake also because i was doing this first test on an example where there is no Javascript at all.

        Next step for me : learn about XPath.
        From what i remember it looks fairly much like a Tree. So i guess i could use similar algorithms. Any major difference ?

        Thanks again for helping me understand :o)
        Now i know where to look, which makes a big difference.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://951071]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2014-07-23 16:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (146 votes), past polls