mardi 21 mars 2017

Geb: Click element with dynamic selector

I have the below code to click a date in a calendar which works fine:

$("div",class:"ui-datepicker-group ui-datepicker-group-last").find("a",class:"ui-state-default",text:random_dep_date.toString()).size()
$("div",class:"ui-datepicker-group ui-datepicker-group-last").find("a",class:"ui-state-default",text:random_dep_date.toString()).click()

Where below does not work:

def selector = "ui-datepicker-group ui-datepicker-group-last"
$("div",class:"${selector}").find("a",class:"ui-state-default",text:random_dep_date.toString()).size()
$("div",class:"${selector}").find("a",class:"ui-state-default",text:random_dep_date.toString()).click() 

Here selector will be changed dynamically like below:

ui-datepicker-group ui-datepicker-group-first
ui-datepicker-group ui-datepicker-group-middle
ui-datepicker-group ui-datepicker-group-last

What is the problem with the second segment of code? Please suggest.

Aucun commentaire:

Enregistrer un commentaire