FireWatir 和 jQuery

发布于 2024-08-22 03:11:06 字数 492 浏览 3 评论 0原文

在使用了 FireWatir 这个优秀的和平软件之后,我想知道是否有一种方法可以将 jQuery-selector-magic 集成到我的测试中。

我的第一次尝试是使用 firewatir 的 js_eval() 方法,就像这样

require 'rubygems'
require 'firewatir'
f = FireWatir::Firefox.new
f.js_eval("alert(42);")

我得到的唯一结果是

JsshSocket::JSReferenceError:警报未定义

这有点奇怪,因为像

f.js_eval("document.location.toString();")

Work 这样的其他表达式就像魅力一样!

有人有提示吗?

谢谢并问候,

after using this excellent peace of software called FireWatir, I wonder if there is a way to integrate jQuery-selector-magic to my test.

My first attempt is to use firewatir's js_eval() method like this

require 'rubygems'
require 'firewatir'
f = FireWatir::Firefox.new
f.js_eval("alert(42);")

The only thing I get is a

JsshSocket::JSReferenceError: alert is not defined

which is kind of strange because other expressions like

f.js_eval("document.location.toString();")

Work like a charm!

Anyone with a hint?

Thanks and greets,

Joe

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

转角预定愛 2024-08-29 03:11:06

如果您想像通常使用 $ 一样使用它,您需要将其包装在一个函数中,该函数将在 widows 文档的上下文中运行它。

var win = new getWindows()[0].content;
var doc = browser.contentDocument;

$ = function(selector) {

  win.content.jQuery(selector, doc);

}

芝加哥网页设计

If you want to use it like you would normally with a $ you need to wrap it in a function which will run it on the context of the widows document.

var win = new getWindows()[0].content;
var doc = browser.contentDocument;

$ = function(selector) {

  win.content.jQuery(selector, doc);

}

chicago web design

此岸叶落 2024-08-29 03:11:06

好的,伙计们,

我对 jQuery 进行了大量的研究,如果您遇到类似的问题,我希望这会对您有所帮助:

firefox.js_eval("var target = getWindows()[0]; target.content.jQuery('#selector').toggle()")

我要做的就是选择我正在使用的窗口,并且在其内容中 jQuery 可用并且一个人能够利用它所有的威力! ;)

问候

Okay folks,

i got jQuery working with a lot of researching and I hope this will be help you out if you have similar problems:

firefox.js_eval("var target = getWindows()[0]; target.content.jQuery('#selector').toggle()")

What i had to do was to select the window I am working in explicitly and within its content jQuery is available and one is able to use all of its awesomeness! ;)

Greetings
Joe

旧话新听 2024-08-29 03:11:06

来自 FireWatir Wiki

FireWatir 将代码转换为等效的 JavaScript,然后将其传输到 JSSh 服务器并针对浏览器中加载的页面的 DOM 执行。

alert 函数属于浏览器的 window 对象,而不是页面的 DOM。因此,您可以调用类似 window.alert('hello dollly') 的警报。

FireWatir 创建一个 JSSh 会话,将您的 js_eval 发送到 DOM,因此无法与窗口交互。

From the FireWatir Wiki:

FireWatir translates code into a JavaScript equivalent, which is then transmitted to the JSSh server and executed against the DOM of the page loaded in the browser.

The alert function belongs to the window object of a browser, not the DOM of the page. So you can call an alert like window.alert('hello dollly').

FireWatir creates a JSSh session, that sends your js_eval to the DOM, therefore unable to interact with the window.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文