exploring html source through the shell

2 views
Skip to first unread message

Kern

unread,
Sep 6, 2008, 8:59:10 PM9/6/08
to Windmill-Dev
Hi,

First of all. great tool. I've found it of much use so far. I was just
wondering whether it is possible to explore the DOM interactively via
the shell. If so, how would I go about doing that?

Please let me know.

Thanks.

Adam Christian

unread,
Sep 6, 2008, 10:39:52 PM9/6/08
to windmi...@googlegroups.com
Using firebug, or the shell you can explore the DOM, from the IDE the
pointer to the test application is windmill.testWindow, or opener or
_w, they all point at the window object of the test app. To explore
the page you can do many things:

_w.document.body will get you to the page content, then .childNodes
will give you all the child nodes. You can also do
_w.document.getElementById('id') and that will let you access the node
directly.. you should look at javascript and DOM for more information
on available methods.

Does this answer your question?

Adam

Kern Handa

unread,
Sep 7, 2008, 12:33:21 AM9/7/08
to windmi...@googlegroups.com
Thanks for your answer. Could you provide an example of how one would
explore the DOM through the shell?

Thanks!

Adam Christian

unread,
Sep 7, 2008, 12:41:00 AM9/7/08
to windmi...@googlegroups.com, windmi...@googlegroups.com
Using the console in the new Firebug lite an example of exploring the
document in the shell:

dir(_w.document)

This will give you a list of all the attributes, you can use dir on
any DOM element.

Another example is:

dir(_w.document.getElementById('nodeID'))

Is there something you are specifically trying to do?

Adam

Mikeal Rogers

unread,
Sep 7, 2008, 1:20:09 AM9/7/08
to windmi...@googlegroups.com
What is the particular use case you're doing?

When I'm creating a test I usually just use the inspector to write
test actions on a particular element. If I want to create and
assertion that something in the DOM is the way that I think it should
be I usually use Firebug Lite (on windmill 0.8.2 click the "Firebug"
link and then in the main app window hitting the Inspect button) and I
find what DOM properties/values would assert what I want. Then I use
IDE inspector again to write an assertion for whatever I figured out.

I hope that helps, it might just confuse things more.

Adam, I think a screencast might be in order?

-Mikeal

Adam Christian

unread,
Sep 7, 2008, 1:35:16 AM9/7/08
to windmi...@googlegroups.com
Yes, I think this is a good opportunity to start some short screen
casts demonstrating features.

I'll send a link to the list when I get something up monday.

Adam

Kern Handa

unread,
Sep 7, 2008, 6:30:51 AM9/7/08
to windmi...@googlegroups.com
Sorry, it seems I'm not understanding too well. Just to clarify, by
shell I meant the python/ipython shell. Is there some special process
that needs to be done to enable the _w or windmill.testWindow variable?
Currently I am not able to access either. i started windmill with
'windmill -pm shell firefox <url>', just in case I need to pass some
particular options.

Thanks for the help!

Adam Christian

unread,
Sep 7, 2008, 4:10:51 PM9/7/08
to windmi...@googlegroups.com
Ahh, thanks for clarifying -- we both thought you were talking about
the javascript shell or console in the IDE.

To access the DOM loaded in the browser via the python shell you can
do the following:


windmill -pm shell firefox <url>

xmlrpc_client.execute_command({"method":"commands.execJS", "params":
{"code":"_w.document.body.innerHTML;"}})

That will return you a dump of the body contents. Anything you can do
in JS that returns a string can be substituted in the code param.

Another example would be:
xmlrpc_client.execute_command({"method":"commands.execJS", "params":
{"code":"_w.document.body.childNodes[0].innerHTML;"}})

We don't currently have a method for returning a list of attributes of
a node, but if thats what you are looking for it wouldn't be too
difficult to add, so let me know.

Hope we are on the right track now.

Adam

Reply all
Reply to author
Forward
0 new messages