I followed the thread and tried the techniques as suggested (i.e. 
ie.alert.close) and also experienced problems.
My browser: Chrome.  The error fails right after the click.
 
Sample code
require 'rubygems'
require 'watir-webdriver'
require "watir-webdriver/extensions/alerts" 
ie.text_field(:id,'login').set('666')
ie.text_field(:id,'password').set('bad')
ie.button(:id,'login').click
puts ie.alert.exists?.to_s
ie.alert.close
 
Error stream:
[0627/131145:ERROR:automation_json_requests.cc(62)] JSON request failed: 
ExecuteJavascript
    with error: Command blocked by an open modal dialog
c:/ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/response.rb:50:in
 
`assert_ok': Script execution failed. Script: window.alert = function(msg) 
{ window.__lastWatirAlert = msg; }; 
(Selenium::WebDriver::Error::UnknownError)
 Internal Chrome error during 'ExecuteJavascript': (Command blocked by an 
open modal dialog). Request details: 
({"command":"ExecuteJavascript","frame_xpath":"","javascript":"window.domAutomationController.send((function(){return
 
function(){var i=void 0,l=null,n,p=this;function q(){}\nfunction r(a){var 
b=typeof a;if(b==\"object\")if(a){if(a instanceof 
Array)return\"array\";else if(a instanceof Object)return b;var 
c=Object.prototype.toString.call(a);if(c==\"[object 
Window]\")return\"object\";if(c==\"[object Array]\"||typeof 
a.length==\"number\"&&typeof a.splice!=\"undefined\"&&typeof 
a.propertyIsEnumerable!=\"undefined\"&&!a.propertyIsEnumerable(\"splice\"))return\"array\";if(c==\"[object
 
Function]\"||typeof a.call!=\"undefined\"&&typeof 
a.propertyIsEnumerable!=\"undefined\"&&!a.propertyIsEnumerable(\"call\"))return\"function\"}else
 
return\"null\";\nelse if(b==\"function\"&&typeof 
a.call==\"undefined\")return\"object\";return b}function aa(a){var 
b=r(a);return b==\"array\"||b==\"object\"&&typeof 
a.length==\"number\"}function t(a){return typeof a==\"string\"}function 
ba(a){a=r(a);return a==\"object\"||a==\"array\"||a==\"function\"}function 
u(a){return a[ca]||(a[ca]=++da)}var 
ca=\"closure_uid_\"+Math.floor(Math.random()*2147483648).toString(36),da=0,ea=Date.now||function(){return+new
 
Date};\nfunction v(a,b){function 
c(){}c.prototype=b.prototype;a.u=b.prototype;a.prototype=new c};function 
fa(a){for(var b=1;b\u003Carguments.length;b++)var 
c=String(arguments[b]).replace(/\\$/g,\"$$$$\"),a=a.replace(/\\%s/,c);return 
a}\nfunction ga(){for(var 
a=0,b=String(ha).replace(/^[\\s\\xa0]+|[\\s\\xa0]+$/g,\"\").split(\".\"),c=String(\"5.7\").replace(/^[\\s\\xa0]+|[\\s\\xa0]+$/g,\"\").split(\".\"),e=Math.max(b.length,c.length),f=0;a==0&&f\u003Ce;f++){var
 
d=b[f]||\"\",h=c[f]||\"\",j=RegExp(\"(
\\\\d*)(\\\\D*)\",\"g\"),k=RegExp(\"(\\\\d*)(\\\\D*)\",\"g\");do{varg=j.exec(d)||[\"\",\"\",\"\"],o=k.exec(h)||[\"\",\"\",\"\"];if(g[0].length==0&&o[0].length==0)break;a=w(g[1].length==0?0:parseInt(g[1],10),o[1].length==0?0:parseInt(o[1],10))||w(g[2].length==0,o[2].length==0)||w(g[2],o[2])}while(a==\n0)}return
 
a}function w(a,b){if(a\u003Cb)return-1;else if(a\u003Eb)return 1;return 
0};var ia=p.navigator,ja=(ia&&ia.platform||\"\").indexOf(\"Mac\")!=-1;var 
ka=window;function 
x(a){this.stack=Error().stack||\"\";if(a)this.message=String(a)}v(x,Error);x.prototype.name=\"CustomError\";function
 
la(a,b){var c={},e;for(e in a)b.call(i,a[e],e,a)&&(c[e]=a[e]);return 
c}function ma(a,b){var c={},e;for(e in a)c[e]=b.call(i,a[e],e,a);return 
c}function na(a,b){for(var c in a)if(b.call(i,a[c],c,a))return c};function 
y(a,b){x.call(this,b);this.code=a;this.name=z[a]||z[13]}v(y,x);var 
z,oa={NoSuchElementError:7,NoSuchFrameError:8,UnknownCommandError:9,StaleElementReferenceError:10,ElementNotVisibleError:11,InvalidElementStateError:12,UnknownError:13,ElementNotSelectableError:15,XPathLookupError:19,NoSuchWindowError:23,InvalidCookieDomainError:24,UnableToSetCookieError:25,ModalDialogOpenedError:26,NoModalDialogOpenError:27,ScriptTimeoutError:28,InvalidSelectorError:32},pa={},A;for(A
 
in 
oa)pa[oa[A]]=A;\nz=pa;y.prototype.toString=function(){return\"[\"+this.name+\"] 
\"+this.message};function 
B(a,b){b.unshift(a);x.call(this,fa.apply(l,b));b.shift();this.B=a}v(B,x);B.prototype.name=\"AssertionError\";function
 
qa(a,b){if(!a){var c=Array.prototype.slice.call(arguments,2),e=\"Assertion 
failed\";if(b){e+=\": \"+b;var f=c}throw new B(\"\"+e,f||[]);}};var 
ra=Array.prototype;function 
sa(a,b){if(t(a)){if(!t(b)||b.length!=1)return-1;return 
a.indexOf(b,0)}for(var c=0;c\u003Ca.length;c++)if(c in a&&a[c]===b)return 
c;return-1}function C(a,b){for(var 
c=a.length,e=Array(c),f=t(a)?a.split(\"\"):a,d=0;d\u003Cc;d++)d in 
f&&(e[d]=b.call(i,f[d],d,a));return e};var D;function 
E(){ta&&(F[u(this)]=this)}var 
ta=!1,F={};E.prototype.o=!1;E.prototype.g=function(){if(!this.o&&(this.o=!0,this.d(),ta)){var
 
a=u(this);if(!F.hasOwnProperty(a))throw Error(this+\" did not call the 
goog.Disposable base constructor or was disposed of after a 
clearUndisposedObjects call\");delete 
F[a]}};E.prototype.d=function(){};function 
G(a,b){E.call(this);this.type=a;this.currentTarget=this.target=b}v(G,E);G.prototype.d=function(){delete
 
this.type;delete this.target;delete 
this.currentTarget};G.prototype.l=!1;G.prototype.z=!0;function 
H(a,b){a&&this.i(a,b)}v(H,G);n=H.prototype;n.target=l;n.relatedTarget=l;n.offsetX=0;n.offsetY=0;n.clientX=0;n.clientY=0;n.screenX=0;n.screenY=0;n.button=0;n.keyCode=0;n.charCode=0;n.ctrlKey=!1;n.altKey=!1;n.shiftKey=!1;n.metaKey=!1;n.w=!1;n.p=l;\nn.i=function(a,b){var
 
c=this.type=a.type;G.call(this,c);this.target=a.target||a.srcElement;this.currentTarget=b;var
 
e=a.relatedTarget;if(!e)if(c==\"mouseover\")e=a.fromElement;else 
if(c==\"mouseout\")e=a.toElement;this.relatedTarget=e;this.offsetX=a.offsetX!==i?a.offsetX:a.layerX;this.offsetY=a.offsetY!==i?a.offsetY:a.layerY;this.clientX=a.clientX!==i?a.clientX:a.pageX;this.clientY=a.clientY!==i?a.clientY:a.pageY;this.screenX=a.screenX||0;this.screenY=a.screenY||0;this.button=a.button;this.keyCode=a.keyCode||\n0;this.charCode=a.charCode||(c==\"keypress\"?a.keyCode:0);this.ctrlKey=a.ctrlKey;this.altKey=a.altKey;this.shiftKey=a.shiftKey;this.metaKey=a.metaKey;this.w=ja?a.metaKey:a.ctrlKey;this.state=a.state;this.p=a;delete
 
this.z;delete 
this.l};n.d=function(){H.u.d.call(this);this.relatedTarget=this.currentTarget=this.target=this.p=l};function
 
ua(){}var 
va=0;n=ua.prototype;n.key=0;n.f=!1;n.m=!1;n.i=function(a,b,c,e,f,d){if(r(a)==\"function\")this.q=!0;else
 
if(a&&a.handleEvent&&r(a.handleEvent)==\"function\")this.q=!1;else throw 
Error(\"Invalid listener 
argument\");this.j=a;this.t=b;this.src=c;this.type=e;this.capture=!!f;this.v=d;this.m=!1;this.key=++va;this.f=!1};n.handleEvent=function(a){if(this.q)return
 
this.j.call(this.v||this.src,a);return 
this.j.handleEvent.call(this.j,a)};function 
I(a,b){E.call(this);this.r=b;this.b=[];if(a\u003Ethis.r)throw 
Error(\"[goog.structs.SimplePool] Initial cannot be greater than 
max\");for(var 
c=0;c\u003Ca;c++)this.b.push(this.a?this.a():{})}v(I,E);I.prototype.a=l;I.prototype.n=l;I.prototype.getObject=function(){if(this.b.length)return
 
this.b.pop();return this.a?this.a():{}};function 
K(a,b){a.b.length\u003Ca.r?a.b.push(b):wa(a,b)}function 
wa(a,b){if(a.n)a.n(b);else if(ba(b))if(r(b.g)==\"function\")b.g();else 
for(var c in b)delete 
b[c]}\nI.prototype.d=function(){I.u.d.call(this);for(var 
a=this.b;a.length;)wa(this,a.pop());delete this.b};var 
xa,ha=(xa=\"ScriptEngine\"in 
p&&p.ScriptEngine()==\"JScript\")?p.ScriptEngineMajorVersion()+\".\"+p.ScriptEngineMinorVersion()+\".\"+p.ScriptEngineBuildVersion():\"0\";var
 
L,M,N,ya,O,P,Q,R;\n(function(){function a(){return{c:0,e:0}}function 
b(){return[]}function c(){function a(b){return h.call(a.src,a.key,b)}return 
a}function e(){return new ua}function f(){return new H}var 
d=xa&&!(ga()\u003E=0),h;ya=function(a){h=a};if(d){L=function(a){K(j,a)};M=function(){return
 
k.getObject()};N=function(a){K(k,a)};O=function(){K(g,c())};P=function(a){K(o,a)};Q=function(){return
 
m.getObject()};R=function(a){K(m,a)};var j=new I(0,600);j.a=a;var k=new 
I(0,600);k.a=b;var g=new I(0,600);g.a=c;var o=new I(0,600);\no.a=e;var 
m=new I(0,600);m.a=f}else L=q,M=b,P=O=N=q,Q=f,R=q})();var 
S={},T={},U={},V={};function za(a,b,c,e){if(!e.h&&e.s){for(var 
f=0,d=0;f\u003Ce.length;f++)if(e[f].f){var 
h=e[f].t;h.src=l;O(h);P(e[f])}else 
f!=d&&(e[d]=e[f]),d++;e.length=d;e.s=!1;d==0&&(N(e),delete 
T[a][b][c],T[a][b].c--,T[a][b].c==0&&(L(T[a][b]),delete 
T[a][b],T[a].c--),T[a].c==0&&(L(T[a]),delete T[a]))}}function Aa(a){if(a in 
V)return V[a];return V[a]=\"on\"+a}\nfunction Ba(a,b,c,e,f){var 
d=1,b=u(b);if(a[b]){a.e--;a=a[b];a.h?a.h++:a.h=1;try{for(var 
h=a.length,j=0;j\u003Ch;j++){var 
k=a[j];k&&!k.f&&(d&=W(k,f)!==!1)}}finally{a.h--,za(c,e,b,a)}}return 
Boolean(d)}\nfunction W(a,b){var c=a.handleEvent(b);if(a.m){var 
e=a.key;if(S[e]){var f=S[e];if(!f.f){var 
d=f.src,h=f.type,j=f.t,k=f.capture;d.removeEventListener?(d==p||!d.A)&&d.removeEventListener(h,j,k):d.detachEvent&&d.detachEvent(Aa(h),j);d=u(d);j=T[h][k][d];if(U[d]){var
 
g=U[d],o=sa(g,f);o\u003E=0&&(qa(g.length!=l),ra.splice.call(g,o,1));g.length==0&&delete
 
U[d]}f.f=!0;j.s=!0;za(h,k,d,j);delete S[e]}}}return 
c}\nya(function(a,b){if(!S[a])return!0;var c=S[a],e=c.type,f=T;if(!(e in 
f))return!0;var f=f[e],d,h;D===i&&(D=!1);if(D){var 
j;if(!(j=b))a:{j=\"window.event\".split(\".\");for(var 
k=p;d=j.shift();)if(k[d]!=l)k=k[d];else{j=l;break a}j=k}d=j;j=!0 in f;k=!1 
in f;if(j){if(d.keyCode\u003C0||d.returnValue!=i)return!0;a:{var 
g=!1;if(d.keyCode==0)try{d.keyCode=-1;break 
a}catch(o){g=!0}if(g||d.returnValue==i)d.returnValue=!0}}g=Q();g.i(d,this);d=!0;try{if(j){for(var
 
m=M(),J=g.currentTarget;J;J=J.parentNode)m.push(J);h=\nf[!0];h.e=h.c;for(var 
s=m.length-1;!g.l&&s\u003E=0&&h.e;s--)g.currentTarget=m[s],d&=Ba(h,m[s],e,!0,g);if(k){h=f[!1];h.e=h.c;for(s=0;!g.l&&s\u003Cm.length&&h.e;s++)g.currentTarget=m[s],d&=Ba(h,m[s],e,!1,g)}}else
 
d=W(c,g)}finally{if(m)m.length=0,N(m);g.g();R(g)}return d}e=new 
H(b,this);try{d=W(c,e)}finally{e.g()}return d});function Ca(){}\nfunction 
Da(a,b,c){switch(typeof b){case \"string\":Ea(b,c);break;case 
\"number\":c.push(isFinite(b)&&!isNaN(b)?b:\"null\");break;case 
\"boolean\":c.push(b);break;case \"undefined\":c.push(\"null\");break;case 
\"object\":if(b==l){c.push(\"null\");break}if(r(b)==\"array\"){var 
e=b.length;c.push(\"[\");for(var 
f=\"\",d=0;d\u003Ce;d++)c.push(f),Da(a,b[d],c),f=\",\";c.push(\"]\");break}c.push(\"{\");e=\"\";for(f
 
in b)Object.prototype.hasOwnProperty.call(b,f)&&(d=b[f],typeof 
d!=\"function\"&&(c.push(e),Ea(f,c),c.push(\":\"),Da(a,d,c),e=\",\"));\nc.push(\"}\");break;case
 
\"function\":break;default:throw Error(\"Unknown type: \"+typeof b);}}var 
Fa={'\"':'\\\\\"',\"
\\\\\":\"\\\\\\\\\",\"/\":\"\\\\/\",\"\\u0008\":\"\\\\b\",\"\\u000c\":\"\\\\f\",\"\\n\":\"\\\\n\",\"\\r\":\"\\\\r\",\"\\t\":\"\\\\t\",\"\\u000b\":\"\\\\u000b\"},Ga=/\\uffff/.test(\"\\uffff\")?/[\\\\\\\"\\x00-\\x1f\\x7f-\\uffff]/g:/[\\\\\\\"\\x00-\\x1f\\x7f-\\xff]/g;functionEa(a,b){b.push('\"',a.replace(Ga,function(a){if(a
 in Fa)return Fa[a];var 
b=a.charCodeAt(0),f=\"
\\\\u\";b\u003C16?f+=\"000\":b\u003C256?f+=\"00\":b\u003C4096&&(f+=\"0\");returnFa[a]=f+b.toString(16)}),'\"')};function
 X(a){switch(r(a)){case 
\"string\":case \"number\":case \"boolean\":return a;case 
\"function\":return a.toString();case \"array\":return C(a,X);case 
\"object\":if(\"nodeType\"in a&&(a.nodeType==1||a.nodeType==9)){var 
b={};b.ELEMENT=Ha(a);return b}if(\"document\"in a)return 
b={},b.WINDOW=Ha(a),b;if(aa(a))return C(a,X);a=la(a,function(a,b){return 
typeof b==\"number\"||t(b)});return ma(a,X);default:return l}}\nfunction 
Ia(a,b){if(r(a)==\"array\")return C(a,function(a){return Ia(a,b)});else 
if(ba(a)){if(\"ELEMENT\"in a)return Ja(a.ELEMENT,b);if(\"WINDOW\"in 
a)return Ja(a.WINDOW,b);return ma(a,function(a){return Ia(a,b)})}return 
a}function Ka(a){var 
a=a||document,b=a.$wdc_;if(!b)b=a.$wdc_={},b.k=ea();if(!b.k)b.k=ea();return 
b}function Ha(a){var b=Ka(a.ownerDocument),c=na(b,function(b){return 
b==a});c||(c=\":wdc:\"+b.k++,b[c]=a);return c}\nfunction Ja(a,b){var 
a=decodeURIComponent(a),c=b||document,e=Ka(c);if(!(a in e))throw new 
y(10,\"Element does not exist in cache\");var f=e[a];if(\"document\"in 
f){if(f.closed)throw delete e[a],new y(23,\"Window has been 
closed.\");return f}for(var d=f;d;){if(d==c.documentElement)return 
f;d=d.parentNode}delete e[a];throw new y(10,\"Element is no longer attached 
to the DOM\");};function La(a,b,c,e){var e=e||ka,f;try{var d=a,a=t(d)?new 
e.Function(d):e==window?d:new e.Function(\"return 
(\"+d+\").apply(null,arguments);\");var 
h=Ia(b,e.document),j=a.apply(l,h);f={status:0,value:X(j)}}catch(k){f={status:\"code\"in
 
k?k.code:13,value:{message:k.message}}}c&&(a=[],Da(new 
Ca,f,a),f=a.join(\"\"));return f}var Y=\"_\".split(\".\"),Z=p;!(Y[0]in 
Z)&&Z.execScript&&Z.execScript(\"var \"+Y[0]);for(var 
$;Y.length&&($=Y.shift());)!Y.length&&La!==i?Z[$]=La:Z=Z[$]?Z[$]:Z[$]={};; 
return this._.apply(null,arguments);}.apply({navigator:typeof 
window!='undefined'?window.navigator:null}, 
arguments);}).apply(null,[function(){window.alert = function(msg) { 
window.__lastWatirAlert = msg; }\n},[],true]));","tab_index":0,"windex":0}).
  from 
c:/ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/response.rb:15:in
 
`initialize'
  from 
c:/ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/http/common.rb:58:in
 
`new'
  from 
c:/ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/http/common.rb:58:in
 
`create_response'
  from 
c:/ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/http/default.rb:64:in
 
`request'
  from 
c:/ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/http/common.rb:39:in
 
`call'
  from 
c:/ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/bridge.rb:450:in
 
`raw_execute'
  from 
c:/ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/bridge.rb:428:in
 
`execute'
  from 
c:/ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/bridge.rb:236:in
 
`executeScript'
  from 
c:/ruby192/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/common/driver.rb:209:in
 
`execute_script'
  from 
c:/ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.4.1/lib/watir-webdriver/browser.rb:124:in
 
`execute_script'
  from 
c:/ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.4.1/lib/watir-webdriver/extensions/alerts.rb:23:in
 
`alert'
  from C:/Documents and Settings/kpetry/Desktop/Run 
Archive/WATIR-TR-Civicorp-R11/Methods_TR.rb:81:in `Method_DashboardLogin'
  from C:/Documents and Settings/kpetry/Desktop/Run 
Archive/WATIR-TR-Civicorp-R11/TestCase_TRParticpant.rb:1104:in `<main>'
 
My Workaround:  Which just dismisses the popup all together.
 
 require 'rubygems'
require 'watir-webdriver'
require "watir-webdriver/extensions/alerts" 
ie.text_field(:id,'login').set('666')
ie.text_field(:id,'password').set('bad')
ie.alert  do
  # Click the submit button
  ie.button(:id,'login').click
end
# Did we move past the login? No->recover bad login attempt Yes -> move on 
with the test.
 
 

On Tuesday, June 26, 2012 8:24:40 AM UTC-5, Željko Filipin wrote:

> On Tue, Jun 26, 2012 at 3:20 PM, RJ <[email protected]> wrote:
> > Watir::Exception::UnknownObjectException: unable to locate alert 
>
> I did not use the new alert api, so I do not have a lot of experience.
>
> The error message says the alert is not there. Please share more relevant 
> code.
>
> Željko
>

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

[email protected]
http://groups.google.com/group/watir-general
[email protected]

Reply via email to