selecting correct row and click checkbox - playwright

I'm new to playwright and not sure how to approach this issue. I have a table with data, and the first column of each row has a checkbox. I want to be able to select the correct row to click the checkbox. What I'm not sure about is how to get the row.
My table:
| | ID | Name | Phone
| [] | 3745 | Frank Smith | 485-555-9394
| [] | 9394 | Joe Johnson | 384-555-2332
In HTML:
<table>
<thead>
<tr>
<th></th>
<th>ID</th>
<th>Name</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<tr role="row" class="odd">
<td><input type="checkbox" name="personid"></td>
<td>3745</td>
<td>Frank Smith</td>
<td>485-555-9394</td>
</tr>
<tr role="row" class="even">
<td><input type="checkbox" name="personid"></td>
<td>9394</td>
<td>Joe Johnson</td>
<td>384-555-2332</td>
</tr>
</tbody>
</table>
Now, I want to select the checkbox associated with user ID 9394.
My original solution is (in nodejs):
page.locator('table tbody tr': {hasText: '9394'}.locator('td').nth(0).locator('input').check();
However, as you can see in the above example, it will select the row with the phone number that ends in 9394 or it will give me an error because it returned multiple rows.
My other thought is to do something like:
page.locator('table tbody tr td:nth(1)', {hasText: '9394'}). ???
I'm just not sure how to get back to the previous td input in the row to click the checkbox.

Instead of using hasText, you can also define a sub-locator that the elements have to contain and reference it using has.
Assuming the id is always in the second column, you can use the following code:
const idLocator = page.locator('td:nth-child(2)', { hasText: '9394' });
const checkbox = page.locator('table tbody tr', { has: idLocator }).locator('input[type=checkbox]');
await checkbox.check();

Related

read row data on button click using python flask

I want to read the patientid in when the corresponding row button in is clicked. Using the code i could able to get the patientid of 1st row of the table. I wanted to get the corresponding row's patientid
<table id="mytable" class="styled-table">
<thead>
<tr>
<th>Patientid</th>
<th>Name</th>
<th>Path</th>
<th>Category</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for row in value %}
<tr>
<td><input type="hidden" name="patientid" value="{{row[0]}}"> {{ row[0] }}</td>
<td>{{row[1]}}</td>
<td>{{row[2]}}</td>
<td>{{row[3]}}</td>
<td><form action="/get" method="POST"><input type="submit" class="button" value="Generate" name="generate"></a> </td>
</tr>
{% endfor %}
</tbody>
</table>
if request.form.get('generate') == 'Generate':
print('selected')
print(request.form.get("patientid"))
a=request.form.get("patientid")
return render_template('automated.html')

Tablesorter - How to ignore sort for certain cell value?

How can I prevent Tablesorter from sorting a certain value or keep these values at the bottom? More specifically, this certain value will always be a -
<table id="myTable" class="tablesorter">
<thead>
<tr>
<th>Name</th>
<th>Number</th>
</tr>
</thead>
<tbody>
<tr>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Bach</td>
<td>40</td>
</tr>
<tr>
<td>Doe</td>
<td>-</td>
</tr>
</tbody>
</table>
I want to keep Doe with the value "-" always at the bottom.
Tablesorter has an emptyTo option which can modify the sort behavior of empty, or non-numeric, cells (demo)
In this case, you might need to set a data-text attribute (modified by the textAttribute option to an empty string.
HTML
<td data-text="">-</td>
JS
$('#myTable').tablesorter({
// ...
emptyTo: 'bottom'
});
This worked for me.
Doc: https://mottie.github.io/tablesorter/docs/example-options-headers-digits-strings.html
jQuery(function($) {
$("#myTable").tablesorter({
stringTo: 'bottom'
});
});

different select options depending on the row

I have a table set up like this
<table class="table table-condensed">
<thead>
<tr>
<th>Look</th>
<th>Lease Company</th>
</tr>
</thead>
<tbody data-bind="foreach: leaseApplicationLooks">
<tr>
<td data-bind="text: lookId"></td>
<td><select data-bind="options: $parent.leaseCompanies, optionsText: 'name', optionsValue: 'name', value: leaseCompany" /></td>
</tr>
</tbody>
</table>
My view model:
leaseCompanies(datacontext.lookups.applicationCompanies);
This returns an array with a name, type fields
Depending on the row I want to display different options:
For example:
Row 1, show all Type = 1, 2
Row 2, show all Type = 2
How would I go about doing this?
Set up a different array for each of the types you want. If they are dynamic in length then set up child observable arrays of your leaseApplicationLooks and populate those by iterating through you list of lease companies. It's pretty simple actual, just use plain all javascript loops

jquery tablesorter: nested tables

I have nested tables where both the inner and outer tables have rows added to them dynamically. When I trigger an update of an inner table, after the inner table order has been changed, the order of the outer table is also changed. I've created a jsfiddle to demonstrate this:
http://jsfiddle.net/FZLxp/
which is forked from the OS question Nested jQuery Tablesorter tables, all sortable
To see the problem sort the outer table by Make so that Toyota is at the top and then click the "update" button. The update button triggers an update of the inner toyota table but also sorts the outer table as well to reflect the sort direction of the Toyota Doors column.
How can I sort the inner table after adding additional rows without sorting the outer table as well?
<script type="text/javascript">
function updateRW() {
$("#toyota").trigger("update", [true]);
}
</script>
<table class="tablesorter">
<thead>
<tr>
<th>Make</th>
<th>Model</th>
</tr>
</thead>
<tbody>
<tr>
<td>Honda</td>
<td>Accord</td>
</tr>
<tr class="tablesorter-childRow">
<td colspan="2" style="padding: 0 30px 0 30px;">
<table class="tablesorter-child">
<thead>
<tr>
<th>Doors</th>
<th>Colors</th>
</tr>
</thead>
<tbody>
<tr>
<td>Honda 2-Door</td>
<td>Honda Red</td>
</tr>
<tr>
<td>Honda 4-Door</td>
<td>Honda Blue</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>Toyota</td>
<td>Camry</td>
</tr>
<tr class="tablesorter-childRow">
<td colspan="2" style="padding: 0 30px 0 30px;">
<table id="toyota" class="tablesorter-child">
<thead>
<tr>
<th>Doors</th>
<th>Colors</th>
</tr>
</thead>
<tbody>
<tr>
<td>Toyota 2-Door</td>
<td>Toyota Yellow</td>
</tr>
<tr>
<td>Toyota 4-Door</td>
<td>Toyota Green</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<input type=button value="update" onclick="updateRW()">
$(document).ready(function()
{
$("table").tablesorter({selectorHeaders: '> thead > tr > th'});
});
This appears to be a bug in tablesorter!
I've opened an issue so we can track it, and I should have this fixed in the next update.
Thanks for reporting it!

Showing a dynamic table in GSP where column & data comes at run time

getting two arrays from controller and code is --
Sql db = new Sql(dataSource_wldb1) // Create a new instance of groovy.sql.Sql with the DB of the Grails app
def ivrColumns = []
db.eachRow(ivrColumnsQuery) {
rsRow ->
ivrColumns.add(rsRow.name) }
def ivrResults = []
db.eachRow(mssqlQuery) {rows ->
//print rows
ivrResults.add(rows)
}
one has all column names & other has all row data.as below-
return render(view:'xref',model:[ivrcolumns:ivrColumns,ivrresults:ivrResults] )
getting data in below format-
Columns
[ClientKey, Abbr, ConfigKey, Federal, State, DMA, Internal, Wireless, CRssing, CurfewExemption, CampaignID]
Data
[groovy.sql.GroovyResultSetExtension#12f8d75, groovy.sql.GroovyResultSetE
oovy.sql.GroovyResultSetExtension#12f8d75, groovy.sql.GroovyResultSetExtension#1
roovyResultSetExtension#12f8d75, groovy.sql.GroovyResultSetExtension#12f8d75, gr
tSetExtension#12f8d75, groovy.sql.GroovyResultSetExtension#12f8d75, groovy.sql.G
ion#12f8d75, groovy.sql.GroovyResultSetExtension#12f8d75]
view code is---
<g:if test="${ivrcolumns != null }">
<center>Database Location - WLDB1 <br>DB Name - IVR_GUARDIAN </center><br><br>
<table class="table loadTable" >
<thead>
<tr bgcolor="#f0f0f0" >
<g:each in="${ivrcolumns}" status="ii" var="columnivr">
<td nowrap>${columnivr}</td>
</g:each>
</tr>
</thead>
<tbody>
<g:each in="${ivrresults}" status="jj" var="hed">
<tr>
<g:each in="${ivrcolumns}" status="kk" var="col">
<td nowrap>${hed.col}</td> ///please suggest how to do it.
</g:each>
</tr>
</g:each>
</tbody>
</table>
now want to show in GSP page .i am able to display the column but having hard time to display data.not getting how the dot will be used to get correct data to each column.
Will appreciate any help.
thanks
Assuming that's just a sql result, you can just call ${ hed[ col ] } or ${ hed."$col" }

Resources