drkvader
drkvader

Reputation: 163

Ruby / Capybara - How to use a JQuery command in Capybara

I have the following JQuery script that are working in my Chrome console. However, it is not working when I use it in my Capybara test. What am I doing wrong?

Script that works in my console

$('#skuTabNavigation a[href="#tabImages"]').trigger('click');

Script in my Capybara test. Did not work

script = '$("#skuTabNavigation a[href="#tabImages"]").trigger("click")';
page.execute_script(script)

Terminal MAC error Failure/Error: page.execute_script(script)

 Selenium::WebDriver::Error::UnknownError:
   unknown error: Runtime.evaluate threw exception: SyntaxError: missing ) after argument list
     (Session info: headless chrome=73.0.3683.75)
     (Driver info: chromedriver=2.46.628411 (3324f4c8be9ff2f70a05a30ebc72ffb013e1a71e),platform=Mac OS X 10.12.6 x86_64)

Upvotes: 1

Views: 492

Answers (1)

Jay Dorsey
Jay Dorsey

Reputation: 3662

It looks like you need to escape your quotes; you've got 2 sets of double quotes nested inside your capybara script example.

You might try escaping the quotes around tabImages:

script = "$('#skuTabNavigation a[href=\"#tabImages\"]').trigger('click')";

Upvotes: 1

Related Questions