Search code examples
functional-testinggeb

geb: select by existence of attribute


Given the following html:

<a class="foo">
<a class="foo" href="somePonderousJSIDontWantToQuoteInMyTests">

One can select the later from the former using $("a.foo", href: ~/.*/).

Is there a more elegant way of selecting an element, based on whether or not it has a certain attribute?

Thanks!


Solution

  • I don't know if using a CSS3 attribute matcher is more elegant but it's definitelly quicker especialy if your selector would return many elements without the filter because the filtering happens in the browser and not in the jvm as in your approach:

    $("a.foo[href]")