Eric Slick
Eric Slick

Reputation: 319

ReferenceError: Can't find variable: jQuery with Poltergeist/Capybara

What I'm trying to Do

I'm trying to use capybara with poltergeist to log into amazon at this URL...

https://developer.amazon.com/rp/sales.html

Simple enough, except that when I try to submit the form, I get the error... ReferenceError: Can't find variable: jQuery ...

However, the source for jQuery is on the page and should have been loaded.

The code I'm using to log in is this...

  visit "https://developer.amazon.com/rp/sales.html"
  fill_in('ap_email', with: user)
  fill_in('ap_password', with: password)
  click_on('signInSubmit-input')

Submit triggers a javascript call to validate input. This uses jQuery and when it does, the error is thrown.

What I Expected

I expected that when I visited the login page, that jquery would have been loaded with the other javascript on that page.

I have no idea why jQuery would not be loaded at this point. Phantomjs would have loaded the page and loaded the jQuery referenced on the page, no?

Things I've Tried

Timing Issue? - Added sleep after the visit.

Configuration Issue?

I've tried quite a few things in an attempt to get my head around what's going on but I'm coming up empty.

Any thoughts on where I might look or what may be going on would be greatly appreciated.

Upvotes: 31

Views: 3813

Answers (2)

Trinetra-MSFT
Trinetra-MSFT

Reputation: 1015

The execution is sandboxed, the web page has no access to the phantom object and it can't probe its own setting.

Upvotes: 0

alanmbarr
alanmbarr

Reputation: 142

If jQuery is on the page you most likely have to use an evaluate function to enter the context of the page. CasperJS has this diagram http://docs.casperjs.org/en/latest/_images/evaluate-diagram.png http://phantomjs.org/api/webpage/method/evaluate.html

The execution is sandboxed, the web page has no access to the phantom object and it can't probe its own setting.

Upvotes: 1

Related Questions