gpt4 book ai didi

javascript - 引用错误 : Can't find variable: jQuery with Poltergeist/Capybara

转载 作者:可可西里 更新时间:2023-11-01 02:12:50 24 4
gpt4 key购买 nike

我想做什么

我正在尝试使用带有 poltergeist 的 capybara 通过此 URL 登录亚马逊......

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

很简单,除了当我尝试提交表单时,出现错误... ReferenceError:找不到变量:jQuery ...

但是,jQuery 的源代码在页面上并且应该已经加载。

我用来登录的代码是这样的...

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

提交触发 javascript 调用以验证输入。这使用 jQuery,当它使用时,会抛出错误。

我的期望

我预计当我访问登录页面时,jquery 会与该页面上的其他 javascript 一起加载。

我不知道为什么此时不加载 jQuery。 Phantomjs 会加载页面并加载页面上引用的 jQuery,不是吗?

我尝试过的事情

时间问题? - 参观后增加 sleep 。

配置问题?

  • 我当前的配置

    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
  • 尝试强制加载 jQuery

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

我已经尝试了很多东西,试图弄清正在发生的事情,但我一无所获。

如有任何关于我可能查看的位置或可能发生的事情的想法,我们将不胜感激。

最佳答案

如果页面上有 jQuery,您很可能必须使用求值函数来进入页面上下文。 CasperJS 有这张图 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.

关于javascript - 引用错误 : Can't find variable: jQuery with Poltergeist/Capybara,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30496090/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com