Calculate module of index int Struts2 iterator - module

I'm using Struts2 iterator to setup a list of checkbox in a table. I want to have 10 checkbox per row, so I'm doing the following:
<table>
<tr>
<s:iterator value="securityMasterFields" status="fieldNameStatus" var="fieldName">
<s:if test="#fieldNameStatus.index % 10 ==0">
</tr><tr>
</s:if>
<td>
<s:checkbox name="fieldsToShow" fieldValue="%{fieldName}" value="%{fieldName}"/>
</td>
</s:iterator>
</tr>
</table>
It never goes through the if, so I'm assuming the mod is not been calculated correctly. How do I do it?
thanks

Well, I had to add some parentheses and it worked correctly. The loop was working, it was just that it wasn't going through the if.
<s:if test="(#fieldNameStatus.index % 8 )==0"></tr><tr></s:if>

It looks good to me. Two thoughts:
1) try printing the result of the test in s:property tag
2) It looks like you will have empty table rows... Are you looking at the generated html or just the output, because if it is just the output then unless you have some CSS giving you some table padding and borders, without an empty 'td' element the row might collapse and make it appear as if nothing is being added. So do make sure you print the empty 'td' elements too!

Related

Why doesn't my XPath expression return any results?

I have the following html:
<html>
<body>
<table>
<tr>
<tr>
<tr>
<tr>
<tr>
<td>Color Digest </td>
<td>AgArAQICGQMVBBwTIRQHIwg0GUMURAZTBWQJcwV0AoEDAQ </td>
</tr>
<tr>
<td>Color Digest </td>
<td>2,43,2,25,21,28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,33,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, </td>
</tr>
</table>
</body>
</html>
and the following xpath:
tr[td='Color Digest']/td
and I'm getting zero results.
Can someone explain why?
Inside xPath expression we can use attribute name and tag name(when it has text) as well. Here both <tr> and <td> are tag names. The valid xPath expressions be like,
//tagname[#attributeName='value']
and
//tagname[#tagname='text']
Inside td there is only text available so you need to write xPath like
//td[text()='Color Digest ']
or
//tr[td='Color Digest ']
If you need to use specific element then please use the match number like below,
(//td[text()='Color Digest '])[1]
or
(//tr[td='Color Digest '])[1]
Why it showed 0 matches for your xPath?
You haven't given space at end of Digest.
Yours:
//tr[td='Color Digest']/td
Corrected one:
//tr[td='Color Digest ']/td
There are a few issues with your XPath
tr[td='Color Digest']/td
^ 1
^ 2
^ 3
XPaths should start with a / (child) or // (descendant). Child basically means one level down where descendant means one or more levels down.
tr should be //tr in this case since there are no root TRs.
You've used td when it looks like you meant to use . or text() which indicates two variations of text within the element. . means squash the contained text of all descendant nodes and text() means the contained text of just the current node.
Either text() or . will work in this case but I would generally use text() just to be safe.
[td='Color Digest'] should be [text()='Color Digest']
If you look at the HTML you provided, the text in the first TD actually contains a space at the end, e.g. 'Color Digest ' vs 'Color Digest'. That space is required unless you use a function like contains().
[td='Color Digest'] should be [text()='Color Digest ']
For this last one, I'm not sure what you are actually looking for, /td.
For the TD that contains the "Color Digest " text, it has no child. If you meant sibling TD, that would require /following-sibling.
/td should be /following-sibling::td[1].
Putting all of this together,
//tr[text()='Color Digest ']/following-sibling::td[1]
and it would return the following elements
<td>AgArAQICGQMVBBwTIRQHIwg0GUMURAZTBWQJcwV0AoEDAQ </td>
<td>2,43,2,25,21,28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,...</td>

Aurelia: Using index value to increment array value in input binding

I am trying to increment an array value inside a value.bind directive so that, in this example, three rows are created, incrementing the array number:
<tr repeat.for="i of 3">
<td><input type="text" value.bind="GS.qData.estate[**${$index}**].name"></td>
**strong text**</tr>
I have tried several permutations ( {$i}, etc ), but nothing seems to work.
Further research seems to show that the repeater won't do this, so I have other solutions.
Thanks for the reply.

How to find an item in Selenium WebDriver?

I want to find the following item using Selenium. The value of the class changes whenever there is a change. This is inside a complex page (multiple iframes, and other items loaded dynamically). The only unique id is itemid, which is dynamic value and title combination. If I click on this Action, am getting another new set of complex items. I am new to Selenium. How to do that?
HTML:
<td itemid="xxyyy.as123" title="Actions" nowrap="" class="text-button">Actions <img src="../row.gif"></td>
<td itemid="xxyyy.as123" title="Actions" nowrap="" class="text-button button-active">Actions <img src="../row.gif"></td>
<td itemid="xxyyy.as123" title="Actions" nowrap="" class="text-button button-hover">Actions <img src="../row.gif"></td>
The code I tried:
Find by Xpath
var element=driver.FindElement(By.XPath("html/body/div[id='pageContent']/iframe/#document/ht‌ml/frameset/frame[name='detailsDisplay']/#document/html/body/form[name='tableForm‌']/div[id='divToolbarContainer']/div[id='divToolbar']/div[1][class='toolbar']/tab‌​le/tbody/tr/td[title='Actions']"));
Find by Link Text
var element = driver.FindElement(By.LinkText("Actions"));
Any help would be appreciated.
Try
By.CssSelector("td[title="Actions"]");
By.CssSelector("td[itemid="xxyyy.as123"]");
By.CssSelector("td[itemid="xxyyy.as123"][title="Actions"]")
Create Dynamic CSS Selector.
For Example:
driver.FindElement(By.CssSelector("td[itemid$="xxyyy."]")).Click();
Note: In dynamic Elements, there is always a part of locator wich is fixed. we need to generate the locator using this part.
If fixed part is at starting - Use Carrot Character (^)
If fixed part is at Middle - Use Asterisk sign (*)
If fixed part is at End - Use Doller sign ($)
Finally I was able to achieve it, by using the frame names.
driver.SwitchTo().Frame("content").SwitchTo().Frame("detailsDisplay");
var element = driver.FindElement(By.XPath("//*[#id=\"divToolbar\"]/div[1]/table/tbody/tr/td[1]"));
Thanks everyone.

Handling of dynamic ids through selenium webdriver

Automate an application through selenium where id changes dynamically.how can i handle this.Pls help me..
HTML code is:-
<table border="0" cellpadding="0" cellspacing="0" width="1000px">
<tbody><tr id="ctl00_ctl00_MainContent_CarQuoteMainContent_rpQuotes_trSelectedQuote_0">
<td align="center" valign="middle" width="12%">
<input id="ctl00_ctl00_MainContent_CarQuoteMainContent_rpQuotes_chkCompare_0" name="ctl00$ctl00$MainContent$CarQuoteMainContent$rpQuotes$ctl00$chkCompare" type="checkbox">
</td>
In both the cases ( and ), I assume that the first part of the ID is unique. So you can use something like this.
//tr[contains(#id,'ctl00_')] and for input field //input[contains(#id,'ctl00_')].
Those don't look like dynamic IDs, but rather non-content-specific row IDs for elements in a list.
If that's the case, you can't immediately ascertain 'This row element is displaying data for MyCarQuotes.com' from this information alone as there's nothing in the HTML shown to base that query on.
If there's something in the rows you can use to 'identify' the content (eg a company name) - and you have a specific 'thing' you want to interact with - you could encapsulate the lookup and do something like
CheckboxForQuoteFromCompany("MyCarQuotes.com").Click();
If you're able to post more of the HTML (at least a full row), and more importantly the intention of your test, we may be able to be of more help.

DataGrid's rowsPerPage attribute not working

I need to add pagination feature to few of my DataGrids
and I am just moving ahead step by step.
To begin with I tried setting 'rowsPerPage' attribute
of DataGrid to some value, say 5. But it has no impact on the
displayed grid. I mean number of rows displayed are more than
the value set to 'rowsPerPage'.
<table dojoType="dojox.grid.DataGrid" store="tags" rowsPerPage =3
style="width: 100%; height: 500px;">
<thead>
<tr>
<th width="150px" field="dept">Namey</th>
<th width="150px" field="name">Depty</th>
</tr>
</thead>
</table>
Please tell me how to show only 3 results only per time .
I have been searching web since morning but to no avail.
Any inputs will be highly appreciated.
Please help .
The rowsPerPage property actually doesn't control the number of items show in the grid. It controls the number of rows loaded as you scroll through the grid. Default is 25, and that's usually pretty good.
What you want to do is set the autoHeight property on the grid to the number of rows you want to show. It's kind of an interesting property because it can be set to "true" which will expand your grid to show all data rows, or it can be set to a number (like 3) and then it will only show that many rows, and create a scroller for your grid if your data store has more than that number of rows.
(I know this is probably a late answer, but found this while researching another grid question, and thought I'd throw it out there.)