Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass variables to page.executescript() in capybara

Tags:

ruby

capybara

I need to pass the variable in the javascript to be executed through excute_script method in capybara.

I am unable to pass variable to it.

Please anyone help me.

Example:

@idd="sample"
txt=page.execute_script('var user_id = ${@idd}; return user_id;')
puts txt

I am expecting the text sample to be printed but i'm getting java script error.

like image 843
NMKP Avatar asked Dec 13 '12 06:12

NMKP


1 Answers

I think the problem is with ${}; you have to use #{}; try with:

page.execute_script("var user_id = '#{@idd}'; return user_id;")
like image 68
gradenauer Avatar answered Nov 16 '22 02:11

gradenauer