Print Checkboxes list vertically - spring

How can I print the checkbox list vertically?
Currently, it is printing horizontally as shown below.
Subject 1 Subject 2 Subject 3 Subject 4 Subject 5
I want it this way
Subject 2
Subject 4
Subject 5
Here is the code I am using to print it.
<tr>
<td>
<form:checkboxes items="${favouriteList}" path="subjects" ></form:checkboxes>
</td>
</tr>

Related

How to I get the <td> text OR a link from 'a/href' inside the <td> if the td has a link in it

Using IMPORTXML in Google Sheets to get the links from a table/td.
Page Source: (Some of the 'td' contains text with no links, whereas some 'td' have links but no text.)
<tr>
<td>Cameroon - Brazil</td>
</tr>
<tr>
<td>Netherlands - USA</td>
</tr>
<tr>
<td>Winner Group C vs Australia</td>
</tr>
<tr>
<td>France vs Runner-up Group C</td>
</tr>
<tr>
<td>England - Senegal</td>
</tr>
<tr>
<td>Winner Group E vs Runner-up Group F</td>
</tr>
=IMPORTXML(B3,"//table//tr/td/a/#href")
CURRENT OUTPUT : (This extracts all td which has a/href, and omitting which do not have a/href)
1. /match/cameroon-brazil-2022-12-02
2. /match/netherlands-usa-2022-12-03
3. /match/england-senegal-2022-12-04
EXPECTED OUTPUT: (ignore the numbers (#1 to #6) in the output)
Include empty rows (when 'td' doesn't have a/href)
1. /match/cameroon-brazil-2022-12-02
2. /match/netherlands-usa-2022-12-03
3.
4.
5. /match/england-senegal-2022-12-04
6.
OR Include 'td' text (when 'td' doesn't have a/href)
1. /match/cameroon-brazil-2022-12-02
2. /match/netherlands-usa-2022-12-03
3. Winner Group C vs Australia
4. France vs Runner-up Group C
5. /match/england-senegal-2022-12-04
6. Winner Group E vs Runner-up Group F
The second version can be achieved with this XPath-1.0 expression:
//table/tr/td[not(a)] | //table/tr/td/a/#href
It merges the values of <td>s which have no <a> children with the href attributes of the <td>s that have one.
It's output is
/match/cameroon-brazil-2022-12-02
/match/netherlands-usa-2022-12-03
Winner Group C vs Australia
France vs Runner-up Group C
/match/england-senegal-2022-12-04
Winner Group E vs Runner-up Group F

Cypress - click hyperlink on row based on value of two cells

Trying to get a Cypress script to click a hyperlink based on two values - the text of the hyperlink in column 1 and the value of the cell in the second column:
<tbody>
<tr>
<td>Anything</td>
<td>Casualty</td>
</tr>
<tr>
<td>Declined Prospect</td>
<td>Casualty</td>
</tr>
<tr>
<td>Declined Prospect</td>
<td>Package</td>
</tr>
<tr>
<td>Declined Prospect</td>
<td>Casualty</td>
</tr>
<tr>
<td>Irrelevant</td>
<td>Package</td>
</tr>
</tbody>
cy.get('a').contains('Declined Prospect').click()
fails because there's more than one hyperlink with that value. The id is not useful because it's dynamic.
In the example above, I want to click Declined Prospect when the second column is Casualty (but the order of the rows may vary and values in the first and second column are repeated - but only once for the combination).
Any thoughts?
The trick is to target <td>Casualty</td> then click the preceding <td><a>.
There are quite a few ways to get to sibling elements, the simplest in this case is prev().
cy.contains('td', 'Casualty') // target the 'marker' element
.prev() // move to the previous sibling
.click()
Approach from row and move inwards
To target a row with a specific combination of text in some of it's cells, just concatenate the text and use contains().
cy.contains('tr', 'Declined Prospect Casualty') // target unique text within children
This even works when there are other cells with text that's not relevent to the search, e.g
<tr>
<td>Declined Prospect</td>
<td>Casualty</td>
<td>Irrelevent text here</td>
</tr>
Then you can walk down the HTML tree,
cy.contains('tr', 'Declined Prospect Casualty') // target unique text within children
.find('td a') // descendant of previous subject
.click()
I think this can be useful: https://github.com/cypress-io/cypress-xpath
You can create selectors in xpath instead of css and in xpath you can search tree by text. e.g:
cy.xpath("//text() = 'Declined Prospect'")
==================================Edited====================
You can merge couples of xpatch selectors: it will looks like this //tr[td='Casualty']/td/a
Playgroud

How can I select element base on string() in Xpath?

I have an XML like that:
<tr class="TREven">
<td class="Col0">
<span>
<b>Diary Compliance:</b>
Number of Daily Reports completed
<br/>
<i>
* Must be
<u>24</u>
or more
</i>
</span>
</td>
<td class="Col1">
<span class="Red">4 - Not eligible</span>
</td>
</tr>
I don't know how to select "4 - Not eligible" base on my input text (Diary Compliance: Number of Daily Reports completed * Must be 24 or more) which is contained by many child nodes of span before.
Could you help me?
Thanks,
This is alse my trouble
I often use this xpath to get element on cell 2 base on element on cell 1 in a row table like him:
//span[contains(text(),'Diary Compliance: Number of Daily Reports completed * Must be 24 or more')]/../..//span[contains(text(),'4 - Not eligible')]
It's ok until I get trouble when element on cell 1 has lot of format node, I can't pass my exactly text to element on cell 1. In my case, I must use exactly text, not contains text.

Trouble selecting checkbox on website

after a couple of days of trying, and failing, i need some help please.
I'm trying to select a check box on an website, but it doesn't seems to work as I want to.
the check box is part of a row in a table, together with some other data. The idea is that I log in on the site (http://www.apf.asn.au), go to the table, find the numbers I need from my excel sheet, and select the box that is in the row the number is found.
the log in and navigate to table part is working ok, but I can't find the proper way to select the box.
code from the site:
<div class="table">
<div>
<table class="table APFGrid StudentsSearch"
id="ctl00_ContentPlaceHolderMainNoAjax_gvJumpRecordsList"
style="border-collapse: collapse;" border="1" rules="all" cellspacing="0"
<tbody>
<tr>...</tr> 'Header
<tr>
<td>
<span class="clsSelect">
<input
name="ctl00$ContentPlaceHolderMainNoAjax$gvJumpRecordsList$ctl02$chkSelect"
id="ctl00_ContentPlaceHolderMainNoAjax_gvJumpRecordsList_ctl02_chkSelect"
onclick="javascript:ToggleCheckBoxSelection;" type="checkbox"></input>
</span>
</td> 'Box need to check
<td class="Name">...</td>
<td class="Name">...</td>
<td class="DateBirth">...</td>
<td class="APFNum">...</td> 'Number I'm looking for
<td class="JumpType">...</td>
<td class="DateBooked">...</td>
<td>...</td>
<td class="Name">...</td>
</tr>
<tr>...</tr>
Etc.
I use this code:
'Get APF Number from Pipe
xNr = "20819334"
'Search Number online
Dim i As Integer
i = 0
For Each Row In APFtable
If i = 0 Then
Set Member = Row.getElementsByTagName("th")
Else
Set Member = Row.getElementsByTagName("td")
End If
i = i + 1
On Error Resume Next
If xNr = Member(4).innerText Then
'Check the corresponding checkbox
Exit For
End If
Next Row
to compare the number, in my example: xNr, to the numbers in the table. But I can't figure out how to check the box.
I tried this code:
Name = "ctl00$ContentPlaceHolderMainNoAjax$gvJumpRecordsList$ct" & 100 + i & "$chkSelect"
Set Check = IE.Document.GetElementsByName(Name)
If Not Check Is Nothing Then
Check(0).Click
End If
end all the other ways I could find in other forums to get it to work, although this came closest to working. which means that it worked when I hard-coded the name in the variable with out the "calculating position" part.
can someone advice me on my problem?
Much appreciated
Member(4).parentElement.getElementsByTagName("input")(0).Click
Should do it if the checkbox is the first input element on that row.

Find all preceding sibling nodes until one is found with a specific child node attribute

I would like to get all table rows after a specific row identifier (an attribute on the row column) until that specific row identifier is found.
Here is the html I'm trying to parse:
<tr>
<td colspan="4">
<h3>Header 1</h3>
</td>
</tr>
<tr>
<td>Item desc - Header 1</td>
<td>more info</td>
<td>30</td>
<td>500</td>
</tr>
<tr>
<td colspan="4">
<h3>Header 2</h3>
</td>
</tr>
<tr>
<td>Item desc - header 2</td>
<td>other</td>
<td>4</td>
<td>49</td>
</tr>
<tr>
<td>Item 2 desc - header 2</td>
<td>other 2</td>
<td>65</td>
<td>87</td>
</tr>
I want to be able to grab the item under header 1 and stop when it finds header 2; then the items under header 2 and stop when it finds a header 3; etc.
Is this possible under xpath? I can't get it to only find the TR nodes until it finds a child node with a specific attribute (of colspan="4").
This is not possible under XPath 1.0. You somehow have to fixate the header tr, because you are trying to find all its following siblings whose first preceding header tr is the original one. Without the reference to the original header, everything is possible. But you probably work in some kind of a language that you can use to remember the value.
For example, in xsh:
for my $x in //tr[td/#colspan="4"] {
echo ($x/td/h3) ;
for $x/following-sibling::tr[count(td)=4
and preceding-sibling::tr[count(td)=1][1]=$x]
echo " " (td) ;
}
Output:
Header 1
Item desc - Header 1 more info 30 500
Header 2
Item desc - header 2 other 4 49
Item 2 desc - header 2 other 2 65 87
This might give you what you're looking for, not the most orthodox means though:
//*/tr/td[not(child::h3)]/ancestor::tr
This will give you all the <td> nodes within a <tr> that isn't a header block.
And you can specify the header with:
//*/tr/td[not(child::h3/text()='Header 1')]/ancestor::tr
Or a more general:
//*/tr/td[not(child::h3[contains(text(),'Header')])]/ancestor::tr

Resources