1

I'm using Capybara to fill in a form and download the results.

It's a bit slow when filling in the form, and I want to check if JavaScript is the culprit.

How do I turn off JavaScript?

The Ruby code was something similar to, but not the same as, the following (the following won't reproduce the error message, but it is somewhat slow).

require "capybara"

url = "http://www.hiv.lanl.gov/content/sequence/HIGHLIGHT/highlighter.html"
fasta_text = [">seq1", "gattaca" * 1000, ">seq2", "aattaca" * 1000].join("\n")

session = Capybara::Session.new(:selenium)

# Code similar to this was run several times    
session.visit(url)
session.fill_in('sample', :with => fasta_text)
session.click_on('Submit')

And the error I was getting (with my real code, but not the code I have above) was

Warning: Unresponsive script

A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger, or let the script continue.

Script: chrome://browser/content/tabbrowser.xml:2884

I wasn't running Capybara as part of a test or as part of a spec.

To confirm that the code I wrote currently has JavaScript enabled (which is something I want to disable), doing

url = "http://www.isjavascriptenabled.com"
session = Capybara::Session.new(:selenium)
session.visit(url)

indicates that JavaScript is enabled.

5
  • To clarify: you want to use Selenium to drive a real browser, but with JavaScript disabled? By default, Capybara uses a RackTest driver that does not execute JavaScript, but it also does not drive a real browser. Would that suit? Commented Nov 4, 2014 at 3:33
  • @TimMoore I'm not a web developer, but I assume a RackTest driver wouldn't work on a third party website (I don't run the hiv.lanl.gov site). Commented Nov 4, 2014 at 6:37
  • Ah yes, you are correct. Commented Nov 5, 2014 at 0:18
  • There's a related answer here stackoverflow.com/a/7492504/29470. The example there is for Java, but it should be translatable to Ruby/Capybara. I can try to write up a full answer when I have some more time, but maybe that will get you going. Commented Nov 5, 2014 at 0:21
  • Here's another helpful blog post with some Ruby code yizeng.me/2014/01/08/… Commented Nov 5, 2014 at 0:22

1 Answer 1

1

Capybara only uses JavaScript if you've specified a javascript_browser:

Capybara.javascript_driver = :poltergeist

And if you've specified js: true as metadata in your spec:

context "this is a test", js: true do

Check for both of those things. If they're not there and the test is not running in a browser or using Poltergeist, then it's probably not using JavaScript.

Sign up to request clarification or add additional context in comments.

2 Comments

I've added more details to my question, including an almost-reproduction of the code. I wasn't running it in a spec. Also, even though I hadn't modified javascript_driver=, JavaScript seems to be enabled.
@AndrewGrimm right, here is an open issue to add an option to disable javascript when using poltergeist github.com/teampoltergeist/poltergeist/issues/489

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.