我正在运行watir-经典3.3.0,配置如下:
当我试图在我测试的一个页面上执行以下脚本时,我会得到一个错误
@browser.execute_script "window.confirm = function() { return true; }"错误:
WIN32OLERuntimeError: (in OLE method `execScript': )
OLE error code:80020101 in <Unknown>
Could not complete the operation due to error 80020101.
HRESULT error code:0x80020009
Exception occurred.
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-classic-3.3.0/lib/watir-classic/page-container.rb:46:in `method_missing'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-classic-3.3.0/lib/watir-classic/page-container.rb:46:in `rescue in execute_script'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-classic-3.3.0/lib/watir-classic/page-container.rb:39:in `execute_script'
from (irb):7
from C:/Ruby192/bin/irb:12:in `<main>'当我查看浏览器中的Javascript错误时,会看到以下内容:
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Timestamp: Thu, 3 Jan 2013 16:13:47 UTC
Message: Invalid character
Line: 1
Char: 1
Code: 0
URI: file:///C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-classic-3.3.0/lib/watir-classic/ext/json2.js
Message: 'JSON' is undefined
Line: 1
Char: 1
Code: 0
URI: http://iis01/XXX/employees/default.asp注意:我在错误日志中得到了几次。
该网站没有加载错误,我不知道为什么JSON2是与无效字符身份不明。知道我该怎么解决这个问题吗?
发布于 2013-01-05 14:19:40
我这里没有IE8来试一试,但是你能在你的IE8上试一下吗?
如果其中任何一个是未定义的,或者您得到了一个错误,那么Watir将尝试像在所需的中这样动态地加载json2.js
if (!window.JSON || !window.JSON.stringify) {
var json2=document.createElement('script');
json2.type='text/javascript';
json2.src='file:///C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-classic-3.3.0/lib/watir-classic/ext/json2.js';
document.getElementsByTagName('head')[0].appendChild(json2)
}当您从开发人员工具手动运行该代码时,您能尝试一下会发生什么吗?
如果它成功了,那么也尝试运行JSON.stringify:
JSON.stringify({value: (function() {window.confirm = function() { return true; }})()});发布于 2015-09-17 13:30:54
我尝试了很多东西来解决这个问题,比如修改许多IE (在我的例子中是10节)安全设置。一般来说,使用“保护模式”可以工作,但是Watir的其他部分却不能工作(??)。无论如何,使用CDN版本的json2.js是可行的。这是猴子补丁(我把它放到spec_helper.rb里了)。
module Watir
module PageContainer
private
def with_json2_if_needed source
%Q[
(function() {
if (!window.JSON || !window.JSON.stringify) {
var json2=document.createElement('script');
json2.type='text/javascript';
json2.src='https://cdnjs.cloudflare.com/ajax/libs/json2/20150503/json2.js';
document.getElementsByTagName('head')[0].appendChild(json2)
}
return JSON.stringify({value: (function() {#{source}})()});
})()
]
end
end
endhttps://stackoverflow.com/questions/14142905
复制相似问题