Watir::Safari js eval 等效吗?
我在各种 Watir 中看到并尝试过许多 js eval 的咒语。 ffox 的 firewatir 以及 safariwatir。在 Firefox 中,我可以正常工作,但需要 Safari,因为我的项目是基于 webkit 的。例如,在 Firefox 版本中,我可以执行以下操作:
@browser.document.parentWindow.eval('window.resizeTo(800,600)')
无论如何,我的问题是否有与 js_eval、execute_script 等价的东西,或者从 Watir::Safari 对象访问文档和/或窗口对象?我想做一些事情,比如清除本地存储等。
编辑:
继续并使用 watir-webdriver
require "rubygems"
require "watir-webdriver"
#browser = Watir::Browser.new :ie
#browser = Watir::Browser.new :firefox
@browser = Watir::Browser.new :chrome
@browser.goto "http://google.com"
@browser.text_field(:name, 'q').set "watir-webdriver"
@browser.button(:name, 'btnG').click
@browser.div(:id => "resultStats").wait_until_present
puts "Displaying page: '#{@browser.title}' with results: '#{@browser.div(:id => "resultStats").text}'"
@browser.execute_script('alert("hi");')
I've seen and tried many incantations of js eval in the various Watir's out there. firewatir for ffox, as well as safariwatir. In firefox, I got things working but need Safari as my project is webkit based. For example, in the firefox version I can do stuff like:
@browser.document.parentWindow.eval('window.resizeTo(800,600)')
In any event, my question is there any equivalent to js_eval, execute_script, or access to document and/or window objects from the Watir::Safari object? I would like to do things like clear the local storage, etc.
EDIT:
Went ahead and used watir-webdriver
require "rubygems"
require "watir-webdriver"
#browser = Watir::Browser.new :ie
#browser = Watir::Browser.new :firefox
@browser = Watir::Browser.new :chrome
@browser.goto "http://google.com"
@browser.text_field(:name, 'q').set "watir-webdriver"
@browser.button(:name, 'btnG').click
@browser.div(:id => "resultStats").wait_until_present
puts "Displaying page: '#{@browser.title}' with results: '#{@browser.div(:id => "resultStats").text}'"
@browser.execute_script('alert("hi");')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Chrome 基于 webkit,并与 Watir-Webdriver 配合使用。对于用户来说更重要的是,从安全角度来看,它不像铁丝那样漏洞百出。 (Safari 在过去 4 年里一直保持着完美的记录,成为第一个落入 pwn2own 的浏览器,这是有原因的。)Chrome 的市场份额也是 Safari 的 2.5 到 6 倍(取决于您想要相信的来源)。
如果您需要基于 webkit 的浏览器,为什么不使用 chrome?
我也没有在安全方面开玩笑,我碰巧认识的一位安全专家在一本关于如何进行安全测试的已出版教科书上说“Safari 的唯一好用处就是下载 Firefox 或 Chrome”
Chrome is webkit based, and works with Watir-Webdriver. More importantly to the user, security wise it is not as porous as chickenwire. (there's a reason Safari has an unblemished record for the last 4 years running as the first browser to fall at pwn2own.) Chrome also has (depending on what source you want to believe) between 2.5 to 6 times the market share that Safari does.
If you need a webkit based browser, why not use chrome?
I'm not kidding about the security aspect either, one security expert I happen to know with a published textbook on how to do security testing has said "The only good use for Safari is to download Firefox or Chrome"