6 messages in com.canoo.lists.webtestRe: [Webtest] setSelectField: onclick...
FromSent OnAttachments
Philippe Schoch21 Apr 2006 09:10 
Marc Guillemot25 Apr 2006 00:34 
Philippe Schoch25 Apr 2006 01:44 
Philippe Schoch25 Apr 2006 04:02 
Philippe Schoch25 Apr 2006 04:05 
Marc Guillemot27 Apr 2006 07:56 
Subject:Re: [Webtest] setSelectField: onclick code is executed several times
From:Philippe Schoch (phil@ergon.ch)
Date:04/25/2006 04:02:00 AM
List:com.canoo.lists.webtest

Hi,

I reviewed the code of webtest and htmlunit again and finally I found the fault. It seems to be a bug in webtest. As I searched the open-bug-db I found the bug already reported (WT-143). The problem occurs if an option other than the already selected option gets selected (what is the case most of the time). First time the onchange-event is fired when the actual option is deselected (static method deselectOtherOptions in class SetSelectedField)). The second onchange-event occurs when the new option is selected (in the subsequent calls of method updateOption in class SetSelectedField). Both times the method setSelectedAttribute of class HtmlSelect at HtmlUnit is invoked. And within this method the onchange-handler is activated.

The bug would be quite easy to fix as Htmlunit's comment on the setSelectedAttribute method says that this method internally deselects all other options if an option is selected (in the single-selected mode as a matter of course). That means webtest can erase the deselectOtherOptions method and the bug is fixed as the onchange-event is fired only once...

Cheers, Philippe

Philippe Schoch schrieb:

Hi,

I have a Select-Box (with two options) and some javascript attached:

<select id="Branch:OM_Branch" name="OM_Branch" onchange="document.forms['telcobillForm'].submit(); return false;"> <option value="1">Branch 1</option> <option value="2" selected="selected">Branch 2</option> </select>

Now the webtest step 'setSelectField' is executing the onchange script once, if I choose the first option. That's fine. If I choose the second option, two times a request is sent (means 2x onchange is called) from the same original page (so the second request is sent from an old page as my application is treating the new response as the actual response, not allowing sending requests from the old page). I traced webtest and was getting into htmlunit where the whole js story is executed and where the onchange event is handled. It's not obvious why the js code is executed twice. I even don't know if webtest or htmlunit is responsible for executing the js-code twice.

Had anybody met the same problem? It shouldn't be so unusual to have javascript on a Select-Box.

Here the Output:

[setSelectField] INFO (com.canoo.webtest.steps.Step) - >>>> Start Step: setSelectField "Select the second option" (4/5) [setSelectField] DEBUG (com.canoo.webtest.steps.form.AbstractSetFieldStep) - Looking for element with id "telcobillForm:overview:menu:startMenu:OM_Branch" [setSelectField] DEBUG (com.canoo.webtest.steps.form.AbstractSetFieldStep) - found element with id "telcobillForm:overview:menu:startMenu:OM_Branch": HtmlSelect[<select size="1" name="telcobillForm:overview:menu:startMenu:OM_Branch" onchange="document.forms['telcobillForm'].submit(); return false;" id="telcobillForm:overview:menu:startMenu:OM_Branch" class="dropdown_A_1">] [setSelectField] DEBUG (com.canoo.webtest.steps.form.SetSelectField) - Searching for the right option in HtmlSelect[<select size="1" name="telcobillForm:overview:menu:startMenu:OM_Branch" onchange="document.forms['telcobillForm'].submit(); return false;" id="telcobillForm:overview:menu:startMenu:OM_Branch" class="dropdown_A_1">] [setSelectField] DEBUG (com.canoo.webtest.steps.form.SetSelectField) - Searching option with text: Telenet Branch 2 [setSelectField] DEBUG (com.canoo.webtest.steps.form.SetSelectField) - Examining option: HtmlOption[<option value="1" selected="selected">] [setSelectField] DEBUG (com.canoo.webtest.steps.form.SetSelectField) - Examining option: HtmlOption[<option value="2">] [setSelectField] DEBUG (com.canoo.webtest.steps.form.SetSelectField) - Found option by text: HtmlOption[<option value="2">] [setSelectField] INFO (com.canoo.webtest.engine.Context) - Content of window changed to http://localhost:8080/tb/telcobill.faces [setSelectField] INFO (com.canoo.webtest.engine.Context) - Content of current window changed, it will become current response [setSelectField] INFO (com.canoo.webtest.engine.Context) - Current form set to none [setSelectField] INFO (com.canoo.webtest.engine.Context) - Current response now: http://localhost:8080/tb/telcobill.faces [setSelectField] INFO (com.canoo.webtest.engine.Context) - Content of window changed to http://localhost:8080/tb/telcobill.faces [setSelectField] INFO (com.canoo.webtest.engine.Context) - Content of current window changed, it will become current response [setSelectField] INFO (com.canoo.webtest.engine.Context) - Current form set to none [setSelectField] INFO (com.canoo.webtest.engine.Context) - Current response now: http://localhost:8080/tb/telcobill.faces [setSelectField] DEBUG (com.canoo.webtest.steps.form.SetSelectField) - Selected option: HtmlOption[<option value="2" selected="selected">]

Greets and thanks for all the help, Philippe