-
FEATURED COMPONENTS
First time here? Check out the FAQ!
For enterprise testing I need to write GEB tests on pages produced by ZK. The most important feature for this is to target elements in the html page by their id, so that the test does not need to know about the page structure, just the items it expects to find on the page.
However ZK uses the id for its own internal requirements and the actual value is not fixed. I have tried adding my own attributes to things so I can target those but I get errors.
For example
<radio id="myRadioButton" label ="myLabel" radiogroup="myRadioGroup" myIDAttribute="xyz" />
error org.zkoss.zk.ui.metainfo.PropertyNotFoundException: Method myIDAttribute not found for class org.zkoss.zul.Radio
The best way forward is to surround an element with an xhtml span and give that span an actual id. You can then navigate to the span by id and find the target inside the span. To do this you need to tell the ZUL page to use an xhtml namespace and then tag the span as belonging to that namespace.
First the window tag needs an xmlns attribute targeting the xhtml native namespace:
<window
id="registrationInboxWindow"
title="@load(e.windowTitleText)"
width="100%" height = "100%" border="normal" contentStyle="overflow:auto;"
style="font-size:24px;background-color:#d9e5ef;"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('e') @init('aController')"
mode="overlapped" position="center,top"
xmlns:h="native">
Then you put a native span tag around the target:
<h:span id="trax1">
<radio id="cosRadioButton" label ="Conditions of Service"
radiogroup="travelReasonsRadioGroup" style="color:darkblue"></radio>
</span>
This will produce html that looks like this:
<span id="trax1">
<span class="z-radio" id="e8tRl0" style="color: darkblue;">
<input name="_pgdqdtsp" id="e8tRl0-real" type="radio">
<label class="z-radio-content" id="e8tRl0-cnt" style="color: darkblue;" for="e8tRl0-real">
Conditions of Service
</label>
</span>
</span>
And so GEB can now rapidly find the precise element thus:
conditionsOfServiceRadioButton { $('#trax1').find('input') }
Asked: 2015-10-28 01:31:50 +0800
Seen: 28 times
Last updated: Oct 30 '15
How to get HTML Components values into MVC Composer or MVVM View Model
embed zul file into html template
onBlur event is not sent when clicking on a Html component
Applet integration - How can i get the html tag id in javascript?
Create notification icon with zk 7 CE
I have tried to provide an answer for my own question but it wont let me or explain why. There are not enough characters in comments to demonstrate the answer. Quick version: put xmlns:h="native" in your window tag. Surround elements you want to target with <h:span id="my id">. Find child of span.
Danny4Impact ( 2015-10-29 05:19:55 +0800 )editAh, it says I can post an answer in 20 hours :( Stand by.
Danny4Impact ( 2015-10-29 05:25:42 +0800 )edit