cancel
Showing results for 
Search instead for 
Did you mean: 

how to use a variable in context.expand

SOLVED
Highlighted
Contributor

how to use a variable in context.expand

Can u tell me how to use a variable inside this.

 

def y =1;

 

def g  = context.expand('${Operation#Response#//*//consumerProfile/phoneNumber["+y+"]}');

 

this is not taking 1 as value of y

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: how to use a variable in context.expand

Some other problem with this Xpath then?

 

def y = 1
assert '${Operation#Response#//*//consumerProfile/phoneNumber[' + y + ']}' == 
'${Operation#Response#//*//consumerProfile/phoneNumber[1]}'
4 REPLIES 4
Community Hero

Re: how to use a variable in context.expand

It is already mostly correct, just need to be consistent about the style of quotes:

 

 

def g  = context.expand('${Operation#Response#//*//consumerProfile/phoneNumber[' + y + ']}');
// ^ ^

 

Contributor

Re: how to use a variable in context.expand

That was not working actually
Community Hero

Re: how to use a variable in context.expand

Some other problem with this Xpath then?

 

def y = 1
assert '${Operation#Response#//*//consumerProfile/phoneNumber[' + y + ']}' == 
'${Operation#Response#//*//consumerProfile/phoneNumber[1]}'
Contributor

Re: how to use a variable in context.expand

Thanks it is working now
New Here?
Join us and watch the welcome video:
Top Kudoed Authors