admin管理员组

文章数量:1289548

What I'm trying to Do

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

.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 ".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?

  • My Current Configuration

    include Capybara::DSL
    Capybara.default_driver = :poltergeist
    Capybara.register_driver :poltergeist do |app|
        Capybara::Poltergeist::Driver.new(app, phantomjs: Phantomjs.path)
    end
    Capybara.ignore_hidden_elements = false
    
  • Attempting to Force jQuery to Load

    Capybara::Poltergeist::Driver.new(app,
                                  phantomjs: Phantomjs.path,
                                  extensions: ["handlers/jquery.js"])
    

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

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

What I'm trying to Do

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

https://developer.amazon./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./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?

  • My Current Configuration

    include Capybara::DSL
    Capybara.default_driver = :poltergeist
    Capybara.register_driver :poltergeist do |app|
        Capybara::Poltergeist::Driver.new(app, phantomjs: Phantomjs.path)
    end
    Capybara.ignore_hidden_elements = false
    
  • Attempting to Force jQuery to Load

    Capybara::Poltergeist::Driver.new(app,
                                  phantomjs: Phantomjs.path,
                                  extensions: ["handlers/jquery.js"])
    

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

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

Share Improve this question edited Mar 1, 2020 at 12:21 Nmk 1,3212 gold badges14 silver badges28 bronze badges asked May 28, 2015 at 2:13 Eric SlickEric Slick 3193 silver badges3 bronze badges 8
  • 4 This is probably the best asked question by a new user that is still not answerable without guessing. – Artjom B. Commented May 28, 2015 at 6:25
  • It might be related to SSL and web security. I don't know how this is done in capybara, but you try to pass --ssl-protocol=any --ignore-ssl-errors=true --web-security=false to phantomjs – Artjom B. Commented May 28, 2015 at 6:29
  • Good thought, Artjom, but it didn't help. I think I need to take a different tack and see if a different driver has the same issue. I did try webkit and it had the same error, but maybe actually watching what's going on might reveal something else. – Eric Slick Commented Jun 1, 2015 at 1:28
  • Using selenium with FF, I don't get this error. So, the problem has to be in how I've set things up. Still looking. – Eric Slick Commented Jun 2, 2015 at 19:02
  • No, it's almost certainly a problem with PhantomJS. It always has some kind of problem. Have you tried using PhantomJS 2? – Artjom B. Commented Jun 2, 2015 at 19:05
 |  Show 3 more ments

2 Answers 2

Reset to default 1

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/en/latest/_images/evaluate-diagram.png http://phantomjs/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.

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

本文标签: javascriptReferenceError Can39t find variable jQuery with PoltergeistCapybaraStack Overflow