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/ce07fb22-665b-4b56-9038-4ce5cc1a9512n%40googlegroups.com.

Reply via email to