:facepalm: I should have thought of escaping the $. But otherwise there's 
no getting around it being seen by the compiler as  GString since the CSS 
expression has single quotes, so you have to use doubles for the outside.

I was able to select the radio buttons I wanted, but it turns out that they 
aren't interactable, according to Selenium. When I was doing each one 
individually, I had to set their value (e.g. $('form')['element_name'] = 
'N'). Unfortunately, it doesn't seem that I can assign via the spread 
operator. Is that correct?
On Friday, August 21, 2020 at 9:54:22 AM UTC-5 Thomas Hirsch wrote:

> Hi Ben, 
>
> you can escape a $ in a GString by putting a backslash in front, or 
> alternatively, not use a GString in the first place, by using only single 
> quotes (').
> I haven't double checked the XPath version, sorry for that.
>
> Thomas
>
> On Friday, August 21, 2020 at 4:49:57 PM UTC+2 Ben Frey wrote:
>
>> Cool. Thomas, I tried the CSS selector method and it looks like the 
>> compiler is confused by the $ in the end-of-string selector. I think it's 
>> colliding with Gstrings.
>> I tried the XPath selector but Selenium complained that the string isn't 
>> a valid XPath expression. From some Googling it sounds like the matches 
>> function is XPath 2.0, and still almost nothing supports that version.
>> On Friday, August 21, 2020 at 3:22:23 AM UTC-5 [email protected] 
>> wrote:
>>
>>> Yeah, but you have to be explicit that you are expecting multiple 
>>> elements in the navigator and want to click on all of them by using the 
>>> spread operator otherwise you will get 
>>> a SingleElementNavigatorOnlyMethodException:
>>>
>>> def navigatorWithMultiplelements = $(....)
>>> navigatorWithMultipleElements*.click()
>>>
>>> On Thu, Aug 20, 2020 at 7:36 PM Ben Frey <[email protected]> wrote:
>>>
>>>> Great. And can I then click all of them at once?
>>>>
>>>> On Thursday, August 20, 2020 at 12:57:08 PM UTC-5 [email protected] 
>>>> wrote:
>>>>
>>>>>
>>>>> Hello Ben, 
>>>>>
>>>>> no, you cannot use placeholders like this in CSS selectors, only 
>>>>> direct (partial) comparison.
>>>>>
>>>>> There are two common ways to select WebElements in Selenium (which Geb 
>>>>> is built on top of).
>>>>> 1. By CSS selectors, which is the the default in Geb, if you just pass 
>>>>> a String to the $-method
>>>>> 2. By XPath, which you can do by passing a Selenium-"By"-object to the 
>>>>> $-method, like this: $(By.xpath("//div"))
>>>>>
>>>>> XPath gives you much more options, as it really is a small programming 
>>>>> language, that allows you to traverse the tree of HTML in pretty much any 
>>>>> way you could imagine, including matching of regular expressions.
>>>>>
>>>>> With XPath, it could work like this:
>>>>>
>>>>> $(By.xpath("//*[matches(@name, ' 
>>>>> parentobject.childlist[\\d].thing')]"))
>>>>>
>>>>> i.e. using "\d", which means "digit" in regular expressions as the 
>>>>> wildcard (and escaping that with another backslash because its a 
>>>>> Java-String).
>>>>>
>>>>> Another option, using only CSS selectors, could be to combine a 
>>>>> start-of-string with an end-of-string selector, like this:
>>>>>
>>>>> $("[name^='parentobject.childlist['][name$='].thing']")
>>>>>
>>>>> Best Regards, 
>>>>> Thomas
>>>>>
>>>>>
>>>>> Ben Frey schrieb am Donnerstag, 20. August 2020 um 16:28:39 UTC+2:
>>>>>
>>>>>> From the concrete example at 
>>>>>> https://gebish.org/manual/current/#the-code-code-function, it sounds 
>>>>>> like attribute matching is exact, although it's not super clear that 
>>>>>> this 
>>>>>> is indeed the case. Is this a correct assumption?
>>>>>>
>>>>>> If matching is exact, is there any way to match with a wildcard? I'm 
>>>>>> working on automating a page that's built with YUI, and the name 
>>>>>> attributes 
>>>>>> for elements are built from Java objects, so for example 
>>>>>> name="parentobject.childlist[0].thing". Is there a way to select all 
>>>>>> indices of the childlist, like name="parentobject.childlist[*].thing"?
>>>>>
>>>>> -- 
>>>> 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 view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/geb-user/f048c375-22eb-4220-b29d-28e019fc86e2n%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/geb-user/f048c375-22eb-4220-b29d-28e019fc86e2n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/geb-user/1260a9e6-72b9-40bc-874c-930d62be0963n%40googlegroups.com.

Reply via email to