From: Brad C. <yo...@br...> - 2005-03-17 15:52:59
|
don't use "formElement.focus()", but instead use something like "document.getElementById('myElement').focus()" --- Zhenrong Liu <Zhe...@sa...> wrote: > Brad, > > Would you please be more specific? > > Thanks, > -Zhenrong > > -----Original Message----- > From: htm...@li... > [mailto:htm...@li...] On Behalf Of Brad Clarke > Sent: Tuesday, March 15, 2005 2:22 PM > To: htm...@li... > Subject: Re: [Htmlunit-user] focus is not a function? > > It's likely that we're not handling the context properly during the setTimeout: > > window.setTimeout("formElement.focus();", 400); > > Could you try re-locating your element instide the setTimeout instead of using the > variable? > > > > --- Zhenrong Liu <Zhe...@sa...> wrote: > > > Hey, > > > > I have a test case which will test invalid text input: after enter an > > invalid value in the text input, then click run button, an alert will > > show up and after you click OK in the alert wondow, the focus will go > > back to the input text field for new input. > > .... > > final HtmlPage page3 = (HtmlPage)input.click(); > > assertEquals(handler.getCollectedAlerts().size(), 1); > > .... > > The test passed the assertEquals(), but I got JavaScriptException from console: > > > > ==>> JavaScriptEngine, JavaScriptException occurred: > > ======= EXCEPTION START ======== > > EcmaError: lineNumber=[1] column=[0] lineSource=[GargoyleWrapper2()] > > name=[TypeError] sourceName=[)] message=[TypeError: focus is not a function. > > ()#1)] > > com.gargoylesoftware.htmlunit.ScriptException: TypeError: focus is not a > function. > > ()#1) > > at > > > com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:310) > > at > > > com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:709) > > at com.gargoylesoftware.htmlunit.javascript.host.Window$1.run(Window.java:274) > > at java.lang.Thread.run(Unknown Source) Enclosed exception: > > org.mozilla.javascript.EcmaError: TypeError: focus is not a function. ()#1) > > at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3240) > > at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3230) > > at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3246) > > at org.mozilla.javascript.ScriptRuntime.typeError1(ScriptRuntime.java:3258) > > at > org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3317) > > at > > > org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:1987) > > at org.mozilla.javascript.optimizer.OptRuntime.callProp0(OptRuntime.java:114) > > at org.mozilla.javascript.gen.c16._c1(Wrapper definition for > > Window.setTimeout():1) > > at org.mozilla.javascript.gen.c16.call(Wrapper definition for > > Window.setTimeout()) > > at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:105) > > at org.mozilla.javascript.gen.c17._c0(Window.setTimeout():1) > > at org.mozilla.javascript.gen.c17.call(Window.setTimeout()) > > at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:304) > > at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2769) > > at org.mozilla.javascript.gen.c17.call(Window.setTimeout()) > > at org.mozilla.javascript.gen.c17.exec(Window.setTimeout()) > > at org.mozilla.javascript.Context.evaluateString(Context.java:1220) > > at > > > com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:304) > > at > > > com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:709) > > at com.gargoylesoftware.htmlunit.javascript.host.Window$1.run(Window.java:274) > > at java.lang.Thread.run(Unknown Source) == CALLING JAVASCRIPT == > > GargoyleWrapper2() > > ======= EXCEPTION END ======== > > Mar 15, 2005 1:48:17 PM > > com.gargoylesoftware.htmlunit.javascript.host.Window$1 run > > SEVERE: Caught exception in Window.setTimeout() ======= EXCEPTION > > START ======== > > EcmaError: lineNumber=[1] column=[0] lineSource=[GargoyleWrapper2()] > > name=[TypeError] sourceName=[)] message=[TypeError: focus is not a function. > > ()#1)] > > com.gargoylesoftware.htmlunit.ScriptException: TypeError: focus is not a > function. > > ()#1) > > at > > > com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:310) > > at > > > com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:709) > > at com.gargoylesoftware.htmlunit.javascript.host.Window$1.run(Window.java:274) > > at java.lang.Thread.run(Unknown Source) Enclosed exception: > > org.mozilla.javascript.EcmaError: TypeError: focus is not a function. ()#1) > > at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3240) > > at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3230) > > at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3246) > > at org.mozilla.javascript.ScriptRuntime.typeError1(ScriptRuntime.java:3258) > > at > org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3317) > > at > > > org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:1987) > > at org.mozilla.javascript.optimizer.OptRuntime.callProp0(OptRuntime.java:114) > > at org.mozilla.javascript.gen.c16._c1(Wrapper definition for > > Window.setTimeout():1) > > at org.mozilla.javascript.gen.c16.call(Wrapper definition for > > Window.setTimeout()) > > at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:105) > > at org.mozilla.javascript.gen.c17._c0(Window.setTimeout():1) > > at org.mozilla.javascript.gen.c17.call(Window.setTimeout()) > > at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:304) > > at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2769) > > at org.mozilla.javascript.gen.c17.call(Window.setTimeout()) > > at org.mozilla.javascript.gen.c17.exec(Window.setTimeout()) > > at org.mozilla.javascript.Context.evaluateString(Context.java:1220) > > at > > > com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:304) > > at > > > com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:709) > > at com.gargoylesoftware.htmlunit.javascript.host.Window$1.run(Window.java:274) > > at java.lang.Thread.run(Unknown Source) == CALLING JAVASCRIPT == > > GargoyleWrapper2() > > ======= EXCEPTION END ======== > > > > I checked the JavaScript and I believe the offfending code is: > > > > if (maxValue != null && elementValue.length != 0 && elementValue > > > maxValue) { > > > > > alert(SAS_substituteL10N(dynamicPP_validate_msg16,elementName,maxValue,maxValExclusiveMessage)); > > showContent(theObject.menuItemName, theObject.menuItemName, > > theObject.contentElementName); > > window.setTimeout("formElement.focus();", 400); > > return true; > > } > > > > But I don't have a clue how to fix this and I was wondering if someone > > can shed some light? > > > > Thanks, > > -Zhenrong > > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide Read honest & candid reviews on > hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > Htmlunit-user mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlunit-user > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_ide95&alloc_id396&op=click > _______________________________________________ > Htmlunit-user mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlunit-user > |