How to use variable inside a selector in webdriver io

662 Views Asked by At

This is my selector for selecting element from second row in a table, which is working fine and returning the element name on using getText

get getSecondRow() {
    return $$('#BookingsData tr:nth-child(2) td span');
  }

I was looking for a way to parametrize this selector to return element from any row whose number is specified.

I tried to find element in third row like

getAnyRow(rowCount) {
    return $$('#BookingsData tr:nth-child(${rowCount}) td span');
  } 

where rowCount=3. But it is not working. Getting an error as - An invalid or illegal selector was specified. Can anyone please help. Thanks in advance

1

There are 1 best solutions below

0
On

Instead of using single quotes ', try using back ticks ` around your element #BookingsData tr:nth-child(${rowCount}) td span