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.
I think the problem is with ${}; you have to use #{}; try with:
page.execute_script("var user_id = '#{@idd}'; return user_id;")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With