JSONWP Element/Elements asymmetrical result handling

41 views
Skip to first unread message

Eric Millin

unread,
Jan 27, 2015, 3:44:25 PM1/27/15
to selenium-...@googlegroups.com
I am working on a project that implements JSONWP.  I noticed in the JSONWP doc that a failed find element query returns a NoSuchElement error, but an elements query does not.  Can someone explain if this is an oversight in the doc or is there a rationale for it?

Thanks

Eric Millin

unread,
Jan 28, 2015, 6:51:37 PM1/28/15
to selenium-...@googlegroups.com
I appreciate any help you can offer since this impacts the support the project I'm working on, Appium, offers for Selenium clients.

David Burns

unread,
Jan 28, 2015, 7:11:34 PM1/28/15
to selenium-...@googlegroups.com, selenium-...@googlegroups.com
The rational is that since you can chain commands you would want to get a meaningful message if it is not found. E.g browser.findElement().click() would error saying element not found. Having it return null would cause a null pointer exception which is poor form as well

Having findElements return an array, even if empty, allows us to create conditionals that we can change flow depending on how many items it returns. Using exceptions as conditionals is shit to be honest. 

Hope that makes sense. 

David


Sent from Mailbox


On Tue, Jan 27, 2015 at 10:24 PM, Eric Millin <er...@saucelabs.com> wrote:

I am working on a project that implements JSONWP.  I noticed in the JSONWP doc that a failed find element query returns a NoSuchElement error, but an elements query does not.  Can someone explain if this is an oversight in the doc or is there a rationale for it?

Thanks

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-develo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/254c2d76-b876-41d5-b1be-191cd0da3d42%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric Millin

unread,
Feb 3, 2015, 8:50:18 AM2/3/15
to selenium-...@googlegroups.com
I see the rationale, though I think it forces undue complexity on the server side for what is best handled in the client. E.g., there's no requirement that a client throw when the server returns a NoSuchElement exception for `findElements`.  It implicitly couples the server response to a specific client implementation since the server is framing its data based on desired client behavior.  Why not provide symmetrical responses and let clients decide how to handle it?

Agree about exceptions as conditionals--it was part of the problem that prompted my question.

Anyway, not a huge deal, just my 2 cents.  Thanks for the explanation :)
Reply all
Reply to author
Forward
0 new messages