zk grid template "model", refers to specific element - java

I have grid with template "model" which takes a list. Each element of list has unique name.
How to refer to specific element by name? Because I want to set that row to be visible or not based on certain condition.

The syntax should be row_name.attribute, in this case:
rowName.visible = condition (true/false)

You can set HTML attributes on ZK elements to be able to refer to them by name but it is a bit of a "hack" because that is not the purpose of how ZK is intended to function.

Related

selenium - extracting value from cell (td)

I'm writing a Java test using cellenium, in order to validate the correctness of data I'm trying to extract the values of the table cells, although all cells have different values and meaning the <td> of all cells look the same and have the same attributes like so:
<td onclick="show_data('2','2','rowDetails.php','myID','434b2410aef9e61d6237dbbe562689a9b84','644');">2</td>
the naive solution would be to extract all tag <td> and then go by index.
Is there a better way?
If your elements have no unique identifier then the common way to solve your problem is by fetching all the TD elements and loop over them. This is something you already seem to be aware of, as you're describing this as: extract all tags and then go by index.
However, your provided example does contain a unique identifier, namely the property of the onclick attribute. By using CSS selectors, don't use XPath, you can do a select based on the property (the value) of the onclick attribute. This should help you to narrow down the elements you are looking for.
For list of CSS Selectors see: http://www.w3schools.com/cssref/css_selectors.asp

Is it possible to receive a collection of data from a JSP to a struts action

I'm writing a Struts 2 based web application where I want the user to paste in a list of IDs that will then be processed on the server. So I currently have a text box to accommodate that. Is there a way I can receive that data as a Collection in my bean rather than a String?
Thanks!
If you have many html elements with the same value on the name attribute, they'll be received by the Struts action as a collection.
Also on your Struts action, you must have a collection whose name is the same as the value of the name attribute of these html elements.
If you want to use a single text area, you should use JavaScript to parse its content and load each element on a hidden element. Each hidden element should have the same name.
If you use textbox or textarea then you should place a delimiter to separate tokens. Then on the server after submit you can split them by delimiter to array. Then you can create a collection from the array.

How can I change my xpath dynamically in Selenium WebDriver?

In my application id is changing dynamically,and name is not given to all elements.
Now I want to apply dynamic way of searching "x path" in different Division in HTML.
Whenever I refresh page , database value can be added or removed from page.
So is there any way for taking dynamic path of one element??
You can use custom XPath or CSSPath.
This path have some condition like "OR", "AND", etc.
You can also use some functions like contains(), text(), not(), etc.
References :
http://www.w3schools.com/xpath/xpath_functions.asp
http://www.w3schools.com/cssref/css_selectors.asp

Selenium IDE - Find link within the same row of a specific text from table

I have a specific table that is within multiple tables, and does not have any unique ID or Name. I'm looking for a dynamic solution to find a specific text that will surely occur only once in the whole document, and get the WebElement of the link (text = Add) within the same row.
The text i'm looking for is in the 1st column, and the link is in the 6th column.
Basically i'm looking for a selenium alternate of nextSibling() with a twist that it has to be a link.
selenium supports XPATH which has the notions of siblings and first children etc. You can iterate but this approach makes it more robust. You can select elements too.
selenium IDE supports XPATH for finding the value or location uniquely in web page and it show notions of siblings and first children etc.
you can used Xpath of that value to find it.

How to generate an HTML table in Sitebricks?

Using Sitebricks, I want to generate a table where one object backs each <td> in a table. The only examples I've seen have one object back an entire <tr> - so the HTML is consistent across each row. I would like to be able to wrap N entries in <tr>.
I don't want to have to have my page object in Sitebricks be aware of the layout of the page (and so have to add indices or structure the items as a List<List<Something>>).
Any ideas?
Edit: This is, of course, not limited to Sitebricks, but is a general question about separation of model from view using web templating systems.
Yep, you can add #Repeat on any tag. The implicit variables index and last are defined for you to do your own logic inside the repeat. You could, for example, add a CSS class if index % 2 == 0 to color even rows differently.
Here is a testcase showing how this works for non-table tags (the tags really don't matter):
https://github.com/dhanji/sitebricks/blob/master/sitebricks-acceptance-tests/src/main/resources/Repeat.html
Seems like you can put the #Repeat in front of anything. I don't think it cares about whether it's a row in a table or a column.
https://github.com/dhanji/sitebricks/blob/master/sitebricks-acceptance-tests/src/main/resources/Repeat.html
If you're trying to keep track of the index so you can emit special stuff every nth row, I don't know.

Categories