Question related to custom attribute with iphen

15 views
Skip to first unread message

Jeff Fagot

unread,
Jun 8, 2018, 5:48:14 PM6/8/18
to Watir General
Hello all,

I am using watir (6.10.2).

 GIVEN HTML :
 <div class="Dashboard_Widget_Toolbar_Item" data-widgetapplicationid="Authentication.Application.431" data-widgetconfigure="What I Want">

Because I am using PageObject, I have been used to create page elements using custom attribute as so:

PAGEOBJECT ELEMENT DEF: Where I simply replace the iphen by an underscore ("-" => "_")
self.div(:my_widget, data_widgetconfigure: "What I Want")

Now you see me coming, when I wanted to validate the value of my attribute, I came across the below:
@browser.my_widget_element.attribute_value(:data_widgetconfigure).nil?
# => true

While the correct way seems to be:
@browser.my_widget_element.attribute_value("data-widgetconfigure").nil?
# => false

My question is to know as to why can't I use the first validation but more importantly why is it not erroring out?

Thanks
Jeff

Titus Fortner

unread,
Jun 8, 2018, 6:32:59 PM6/8/18
to Watir General
Hi Jeff,

Hash keys are immutable, and therefore represented by Symbol instances by Ruby convention. The parameter passed into the method to obtain the value is not immutable, and therefore represented as a String instance. There is no exception because Ruby does not do any type checking by default. We could either do a String conversion or throw an argument error, I'm not sure which is better, honestly. Create an issue on watir github page with your preference and we can discuss the best way to handle it. Better yet, if you can figure out how to do that in the attribute value method yourself you can make a pull request and become a contributor to the protect as well. :)

Jeff Fagot

unread,
Jun 9, 2018, 12:22:29 PM6/9/18
to watir-...@googlegroups.com
Hi Titus,

Thanks for your answer. I'm trying to get myself familiar with the project before logging the issue one way or the other...

Jeff

--
--
Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
In short: search before you ask, be nice.

watir-...@googlegroups.com
http://groups.google.com/group/watir-general
watir-genera...@googlegroups.com
---
You received this message because you are subscribed to a topic in the Google Groups "Watir General" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/watir-general/Dwed6fP6kwM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to watir-genera...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Titus Fortner

unread,
Jun 9, 2018, 12:30:59 PM6/9/18
to Watir General
Well, let us know if we can help. If you want to discuss anything, you can find us in the #watir channel of the Selenium Slack Org: http://seleniumhq.herokuapp.com/

Titus

Jeff Fagot

unread,
Jun 11, 2018, 11:45:06 AM6/11/18
to Watir General
I do not think I am knowledgeable enough to decide what direction to go with this "custom attribute value type" issue. Although as a user personal preference, I believe I certainly would prefer to make it work the way I intended to use it, which if I understand your 2 options would be to do a String conversion.
So before, I go ahead and log the issue, I wanted to confirm with you that I understand properly the 2 suggested options (String conversion vs throwing an argument error)
Reply all
Reply to author
Forward
0 new messages