Yes, that's true, CSS2 attribute selectors are as fast as class or ID based
ones, so there is no performance penalty to using them.
As a side note, since 0.13.0 Geb rewrites map based selectors into
attribute based selectors giving you the ability to use a friendlier syntax
without having to pay with performance for it. Therefore you can use the
following syntax:
$("form", "data-qa": "artist").value("1")
Also, note that I used the value() method to change value of a select
element and not an assignment as you all did in your examples. We are
dealing with a navigator here and we can't use the shorthand syntaxt as if
we were using a name to locate that element instead of an attribute.
On Thursday, 16 June 2016, David Lumpkin <[email protected]> wrote:
> You can use a CSS2 attribute selector instead of a geb attribute selector
> and it will be just as fast class or ID selectors (because it is executed
> by the browser rather than returning all possibilities and filtering in
> Geb).
>
> For your example you should be able to do this:
>
> $("form [data-qa='artist']") = "1"
> $("form [data-qa='artist']") = 2
> $("form [data-qa='artist']") = "Alexander"
>
> On Thursday, June 16, 2016 at 10:02:43 AM UTC-6, micha.kutz wrote:
>>
>> You should not do this since all attribute based selectors are much
>> slower than class or ID based ones.
>>
>> We do something similar, but use "qa" prefixed classes instead.
>>
>> Kind regards
>> Micha
>>
>> Rich Crook <[email protected]> schrieb am Do., 16. Juni 2016, 17:58:
>>
>>> Hi Marcin,
>>>
>>> Ok an example is better, given:
>>>
>>> <form>
>>> <select data-qa="artist">
>>> <option value="1">Ima Robot</option>
>>> <option value="2">Edward Sharpe and the Magnetic Zeros</option>
>>> <option value="3">Alexander</option>
>>> </select>
>>> </form>
>>>
>>> We select options with...
>>>
>>> $("form").attr('[data-qa="artist"]') = "1"
>>> $("form").attr('[data-qa="artist"]') = 2
>>> $("form").attr('[data-qa="artist"]') = "Alexander"
>>>
>>> Right?
>>>
>>> Thanks,
>>> Rich
>>>
>>> On Wednesday, June 15, 2016 at 11:37:09 PM UTC-7, Marcin Erdmann wrote:
>>>
>>>> Rich, can you please explain what you mean by using data-* attributes
>>>> directly? Are you asking how to access them? If that's the question then
>>>> you can use something like $("element selector").attr("data-name").
>>>>
>>>> On Thursday, 16 June 2016, Rich Crook <[email protected]> wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> Is it possible to directly use the data-* attributes only without
>>>>> using the element tag name?
>>>>>
>>>>> Thanks!
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Geb User Mailing List" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> To post to this group, send email to [email protected].
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/geb-user/5bd0ee91-69d4-459f-b62d-1cf8ea8a17f6%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/geb-user/5bd0ee91-69d4-459f-b62d-1cf8ea8a17f6%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Geb User Mailing List" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/geb-user/7c5f3c36-54c6-4562-b50e-a0dbb8edc992%40googlegroups.com
>>> <https://groups.google.com/d/msgid/geb-user/7c5f3c36-54c6-4562-b50e-a0dbb8edc992%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Geb User Mailing List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <javascript:_e(%7B%7D,'cvml','geb-user%[email protected]');>.
> To post to this group, send email to [email protected]
> <javascript:_e(%7B%7D,'cvml','[email protected]');>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/geb-user/23d2dbd2-ead3-4b63-9080-1214946d92e0%40googlegroups.com
> <https://groups.google.com/d/msgid/geb-user/23d2dbd2-ead3-4b63-9080-1214946d92e0%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups "Geb
User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/geb-user/CA%2B52dQRDyDs%2B8RgK9F8yCnhp4RxLdumydm%3D-BvXosoi4TVmKKQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.