Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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 ( #951100=note: print w/ replies, xml ) Need Help??


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

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)


Comment on Re^6: WWW::Mechanize - how to get the position of an element on my screen?
Re^7: WWW::Mechanize - how to get the position of an element on my screen?
by Corion (Pope) on Feb 01, 2012 at 07:28 UTC

    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.

        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 //.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (14)
As of 2014-09-23 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls