views:

171

answers:

3

I'm using selenium in my test suite, but since it's slow to set up, I'd like to prototype my xpaths on live pages, rather than waiting for tests to run. Is there a good way to do this?

  • Firebug's $x xpath seems to not work very well
  • jQuery doesn't seem to support Xpath selectors natively, though it used to in version 1.2.
  • using the native javascript stuff (document.evaluator(...)) is verbose and doesn't return lists, making it irritating to use.

What's a good solution? Perhaps there's a way to use selenium as a nice REPL directly?

+1  A: 

Download the Selenium IDE Firefox plugin. It has what you're looking for and more.

You can enter an xpath, and it'll highlight the resulting elements for you. There's also drop-downs to select the Selenium functions you want to invoke.

It also adds context sensitive entries to your context menu (right click some text, then "AssertEquals" on it for example.)

Koobz
Thanks. That should have been obvious.
Paul Biggar
@Paul Biggar: Why accept (with "Thanks", even) but not up-vote?
Tomalak
@Tomalak you don't have to upvote when accepting. Hence the reason for accepting giving more points than a upvote
AutomatedTester
@Tomalak: I did initially upvote, then remembered my policy of actually trying it out first, and so recinded the upvote. After trying it, I came back, but could no longer upvote because of how the site works. I'm not sure why it does that.
Paul Biggar
Actually, having used this a little more, I don't really like it. Its pretty awkward, but I guess its the only place you can actually try selenium locators.
Paul Biggar
@Paul Biggar: This behavior is a much-discussed "feature" that is in place to prevent a special kind of site abuse (tactical voting). After a very brief grace period, cast votes are unchangeable until the answer has been edited again. I don't like the feature very much, at least not for the "+1,0,+1" voting pattern, but that's how it is.
Tomalak
A: 

Firefinder is a nice plugin too, maybe slightly nicer than firebug, maybe not.

Paul Biggar
+1  A: 

Use the XPather add-on for Firefox. I always use it to check out my XPaths.

Also consider using TestPlan to write your tests. It has Selenium and HTMLUnit as a backend. Since HTMLUnit doesn't open a browser your tests run a lot quicker. Once everything is working with HTMLUnit you can just run in Selenium mode and have the same test work in the browser.

http://testplan.brainbrain.net/

edA-qa mort-ora-y