Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by Corion (Patriarch)
on Feb 01, 2012 at 07:28 UTC ( [id://951136]=note: print w/replies, xml ) Need Help??


in reply to Re^6: 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?

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.

Replies are listed 'Best First'.
Re^8: WWW::Mechanize - how to get the position of an element on my screen?
by mascip (Pilgrim) on Feb 01, 2012 at 23:24 UTC

    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.

      XPath is "just" a query language for trees. When starting out with XPath, I found the analogy to paths in a directory tree helpfull. "*" works the same, "/" works the same. If you don't care about the intermediate directories, use //.

        Thank you ! Same algorithms, other language. Should be fairly simple =o)

        In my searches on internet, i found that Mozilla::Mechanize seems to do this another way. The elements it returns are Mozilla::DOM::HTMLElement, and it gets their position thanks to a QueryInstance.
        I don't know what a DOM:HTMLElement are, nor QueryInstance. I don't have the time to learn these now, and know that i want to use WWW::Mechanize::Firefox, so i could as well forget about it for now.

        I was just wondering if it was equivalent to using XPath in the end, and if a few words could make me understand.
        If not, it's all alright : i now know i should use XPath.
        And if i need to understand these, i'll read a book about it.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-03-19 02:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found