The $() function

26 views
Skip to first unread message

Michael Schaefer

unread,
Apr 23, 2016, 10:19:28 AM4/23/16
to Geb Development Mailing List
Hello Devs, 

First, kudos on a great Groovy project. I pulled the code. I'm learning a lot from what you've built here. I have a couple of quick questions:

1. Would any of your code work with XML with no server? I'd like to parse an XML document, create a DOM and then be able to use the $() function to get back a Navigator object and walk the DOM that way. That possible?

2. If that's not possible, I'd like to write it. Basically I'd like to implement what the Node.js guys have with the Cheerio library, but in Groovy. Can you point me to where you implemented the $() function? I pulled the project into IntelliJ, but as you can imagine, there are literally thousands of instances of $ in the code.  :)

Thanks in advance for any help you can give.

Michael

Marcin Erdmann

unread,
Apr 25, 2016, 1:23:43 PM4/25/16
to geb...@googlegroups.com
I'm on holidays atm, will respond next week.

Marcin
--
You received this message because you are subscribed to the Google Groups "Geb Development Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-dev+u...@googlegroups.com.
To post to this group, send email to geb...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-dev/1a459ced-5897-4708-ba2f-f8f4f038ade8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcin Erdmann

unread,
May 5, 2016, 4:36:41 PM5/5/16
to geb...@googlegroups.com
Hi Michael,

Sorry for the late response, hopefully it's still relevant.

1. No, Geb is designed to drive browsers which consume html content and therefore is not a good fit for parsing XML and using the $() method to walk the result. There are libraries that are better at that, though:
- JSoup can parse xml (http://stackoverflow.com/a/21678382/1856764) and allows to use css selectors for navigation
- Jerry is a similar library and it looks like it also supports parsing XML: http://jodd.org/doc/jerry/

2. The implementation of the $() method is not straightforward and the element lookup itself is delegated to WebDriver's SearchContext in SearchContextBasedBasicLocator. Anyway, given JSoup and Jerry you would be reinventing the wheel by implementing an equivalent of Cheerio, I'm affraid.
Reply all
Reply to author
Forward
0 new messages