Create XPATH for a table data as per the table heading - xpath

I have a table which looks something like below:
table with header and data
In some cases, there is a possibility that some of the columns are missing hence the XPath that we create to get the table data will fetch incorrect data.
For example: If I need to fetch the total revenue the Xpth would be
.//*[#id='sessionForm:dataTable_data']/tr/td[7]/div
But suppose if one column before the "Total Revenue" field is missing then the XPath would change to .//*[#id='sessionForm:dataTable_data']/tr/td[6]/div but in my script, it will give me values for the incorrect column.
The HTML behind the table looks something like below:
<div class="ui-datatable-scrollable-body" tabindex="-1" style="margin-right: 0px; width: 680px;">
<table role="grid">
<thead class="ui-datatable-scrollable-theadclone" style="height: 0px;">
<tr role="row">
<th id="sessionForm:dataTable:userid_clone" class="ui-state-default ui-sortable-column" style="width:58px" aria-label="User Id: activate to sort column ascending" role="columnheader" tabindex="0" aria-sort="other">
<span class="ui-column-title">User Id</span>
</th>
<th id="sessionForm:dataTable:Enterprisename_clone" class="ui-state-default ui-sortable-column" style="width:70px" aria-label="Enterprise: activate to sort column ascending" role="columnheader" tabindex="0" aria-sort="other">
<span class="ui-column-title">Enterprise</span>
</th>
<th id="sessionForm:dataTable:startTime_clone" class="ui-state-default ui-sortable-column" style="width:56px" aria-label="Start Time: activate to sort column ascending" role="columnheader" tabindex="0" aria-sort="other">
<span class="ui-column-title">Start Time</span>
</th>
<th id="sessionForm:dataTable:endTime_clone" class="ui-state-default ui-sortable-column" style="width:60px" aria-label="End Time: activate to sort column ascending" role="columnheader" tabindex="0" aria-sort="other">
<span class="ui-column-title">End Time</span>
</th>
<th id="sessionForm:dataTable:dynamicColumns:1" class="ui-state-default ui-sortable-column" style="width:80px" aria-label="Sale Amt: activate to sort column ascending" role="columnheader" aria-sort="other">
<span class="ui-column-title">Sale Amt</span>
<span class="ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s"/>
</th>
<th id="sessionForm:dataTable:dynamicColumns:2" class="ui-state-default ui-sortable-column" style="width:80px" aria-label="Session ID: activate to sort column ascending" role="columnheader" aria-sort="other">
<span class="ui-column-title">Session ID</span>
<span class="ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s"/>
</th>
</tr>
</thead>
<tbody id="sessionForm:dataTable_data" class="ui-datatable-data ui-widget-content">
<tr class="ui-widget-content ui-datatable-even" role="row" data-ri="0">
<td role="gridcell">
<span title="test_user#mailinator.com1044">test_user#test.com</span>
</td>
<td role="gridcell">
<span title="test_enterprise">test_enterise</span>
</td>
<td role="gridcell">
<div class="numeric">01/29/2018 16:00:00 </div>
</td>
<td role="gridcell">
<div class="numeric">01/29/2018 21:00:00 </div>
</td>
<td role="gridcell">
<span title="0.0">0.0</span>
</td>
<td role="gridcell">
<span title="41">41</span>
</td>
</tr>
<tr class="ui-widget-content ui-datatable-odd" role="row" data-ri="1">
<td role="gridcell">
<span title="abc_user#mailinator.com2754">abc_user#test.com</span>
</td>
<td role="gridcell">
<span title="abc_enterprise">abc_enterprise</span>
</td>
<td role="gridcell">
<div class="numeric">01/23/2018 14:30:00 </div>
</td>
<td role="gridcell">
<div class="numeric">01/23/2018 15:45:00 </div>
</td>
<td role="gridcell">
<span title="0.0">0.0</span>
</td>
<td role="gridcell">
<span title="40">40</span>
</td>
</tr>
This is the partial HTML code just for reference.
I need to create XPath for a table column as per the table header i.e first I read the table header and based on the position on the header I need to get all the values for that column.

You can use something like this:
.//*[#id='sessionForm:dataTable_data']/tr/td[position()=count(//span[#class='ui-column-title' and text()='Total Revenue']/../preceding-sibling::*)+1]/div
In this xpath, it will get the column number of Total Revenue and then use it to get that columns value. So suppose if a column vanishes before it, then the value would automatically decrease by 1.
Hope this helps.

Java example:
// List of title columns
List<WebElement> columns = driver.findElements(By.xpath(".//span[#class='ui-column-title']"));
int i = 1;
boolean stop = False;
WebElement elem = null;
while(i<columns.size() && !stop){
elem = columns.get(i-1);
// if the elem has the title stop the loop
if (elem.getText().equalsIgnoreCase("Total Revenue")){
stop = True;
}
}
// The i variable has the right position to take the values for the column
List<WebElement> Revenue_rows = driver.findElements(By.xpath('.//td[(position() > (i-1)) AND (position()<= i)]'))

Related

laravel multiple input insert

I could not add more than one input value to the database. When the color is selected, the size numbers are listed, I want to save the piece value to these size numbers.
How can I record each input separately?
order_piece table
id|order_id|collection_color_size_barcode_id|piece
HTML code
<div class="table-scrollable" style="font-size: 14px;">
<table class="table">
<thead>
<tr>
<th> size </th>
<th> Barcode </th>
<th> order piece </th>
</tr>
</thead>
<tbody>
#foreach ($collection_color_size_barcode as $collection_color_size_barcode){
<tr>
<td><label class="col-md-3 control-label" style="margin-top: 5px;">{{$collection_color_size_barcode->size}}</label></td>
<td><label class="col-md-3 control-label" style="margin-top: 5px;">{{$collection_color_size_barcode->barcode}}</label></td>
<td>
<div class="col-md-5">
<input type="text" class="form-control input-sm" name="size[][{{$collection_color_size_barcode->id}}][piece]">
</div>
</td>
</tr>
}
</tbody>
</table>
Contoller code
public function OrderAdd(Request $request){
return dd($request->size);
}

Problem with rowspan and page break in DomPDF (nesting loop)

Problem with rowspan and page break in DomPDF (nesting loop), this is my code
How to make nesting array with rowspan for column number and good page break?
I can't seem to find anything in the documentation
//Problem with rowspan and page break in DomPDF (nesting array), this is my code
How to make nesting array with rowspan for column number and good page break?
I can't seem to find anything in the documentation
Problem with rowspan and page break in DomPDF (nesting array), this is my code
How to make nesting array with rowspan for column number and good page break?
I can't seem to find anything in the documentation//
<table class="table" style="table-layout: fixed; width: 100%;" >
<tbody>
<tr>
<td class="text-center" style="width:5%;">
<h6>III.</h6>
</td>
<td colspan="2">
<h6>INFORMASI TENTANG KUALIFIKASI DAN HASIL YANG DICAPAI</h6>
<h6 class="font-italic font-weight-bold">INFORMATION OF QUALIFICATION AND LEARNING OUTCOME
</h6>
</td>
</tr>
<tr>
<td class="text-center" rowspan="10">
<p>3.1</p>
</td>
<td colspan="2">
<p class=" font-weight-bold">Capaian Pembelajaran</p>
<p class="font-italic font-weight-bold">Learning Outcomes</p>
</td>
</tr>
<tr>
<td class="text-center" style="width:50%;">
<p class=" font-weight-bold">Bahasa Indonesia</p>
</td>
<td class="text-center" style="width:50%;">
<p class="font-weight-bold">Bahasa Inggris</p>
</td>
</tr>
#foreach($kcs as $kc)
<tr>
<td class="text-center" style="width:50%;">
<p class=" font-weight-bold">{{$kc->kategori_id}}</p>
</td>
<td class="text-center" style="width:50%;">
<p class="font-weight-bold font-italic">{{$kc->kategori_en}}</p>
</td>
</tr>
#foreach($cps as $cp)
#if($cp->id_ps==$data->id_ps && $kc->id==$cp->id_kategori)
<tr>
<td class="text-center" style="width:50%;">
{!! $cp->cpl_id!!}
</td>
<td class="text-center font-italic" style="width:50%;">
{!! $cp->cpl_en!!}
</td>
</tr>
#endif
#endforeach
#endforeach
</tbody>
</table>

How to prevent a simple table to become one enhanced Laravel grid table

How do I prevent the enhancement of the tables within Laravel ?
I have multiple tables on the current page.
The first table is a fully functional laravel grid table, having filters, the search box, order capable, etc ..
The other tables should be simple tables, but, somehow, they all inherit all the features described above.
The source code of my simple table looks like:
<table id="table_container_user_role_coordonator_id{{$value['id']}}"
class="table-bordered table-striped">
<thead>
<tr>
<th>Farmacia</th>
<th>Au dat</th>
<th>Nu au dat</th>
<th>Procent promovare</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</tbody>
</table>
This is what laravel does to my simple tables:
<div id="table_container_user_role_coordonator_id5_wrapper" class="dataTables_wrapper container-fluid dt-bootstrap4 no-footer"><div class="row"><div class="col-sm-12 col-md-6"><div class="dataTables_length" id="table_container_user_role_coordonator_id5_length"><label>Show <select name="table_container_user_role_coordonator_id5_length" aria-controls="table_container_user_role_coordonator_id5" class="form-control form-control-sm"><option value="10">10</option><option value="25">25</option><option value="50">50</option><option value="100">100</option></select> entries</label></div></div><div class="col-sm-12 col-md-6"><div id="table_container_user_role_coordonator_id5_filter" class="dataTables_filter"><label>Search:<input class="form-control form-control-sm" placeholder="" aria-controls="table_container_user_role_coordonator_id5" type="search"></label></div></div></div><div class="row"><div class="col-sm-12"><table id="table_container_user_role_coordonator_id5" class="table-bordered table-striped dataTable no-footer" role="grid" aria-describedby="table_container_user_role_coordonator_id5_info"><thead>
<tr role="row"><th class="sorting_asc" tabindex="0" aria-controls="table_container_user_role_coordonator_id5" rowspan="1" colspan="1" style="width: 55px;" aria-sort="ascending" aria-label="Farmacia: activate to sort column descending">Farmacia</th><th class="sorting" tabindex="0" aria-controls="table_container_user_role_coordonator_id5" rowspan="1" colspan="1" style="width: 39.8167px;" aria-label="Au dat: activate to sort column ascending">Au dat</th><th class="sorting" tabindex="0" aria-controls="table_container_user_role_coordonator_id5" rowspan="1" colspan="1" style="width: 58.7px;" aria-label="Nu au dat: activate to sort column ascending">Nu au dat</th><th class="sorting" tabindex="0" aria-controls="table_container_user_role_coordonator_id5" rowspan="1" colspan="1" style="width: 115.15px;" aria-label="Procent promovare: activate to sort column ascending">Procent promovare</th></tr>
</thead>
<tbody>
<tr role="row" class="odd">
<td class="sorting_1">1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr></tbody>
</table><div id="table_container_user_role_coordonator_id5_processing" class="dataTables_processing card" style="display: none;">Processing...</div></div></div><div class="row"><div class="col-sm-12 col-md-5"><div class="dataTables_info" id="table_container_user_role_coordonator_id5_info" role="status" aria-live="polite">Showing 1 to 1 of 1 entries</div></div><div class="col-sm-12 col-md-7"><div class="dataTables_paginate paging_simple_numbers" id="table_container_user_role_coordonator_id5_paginate"><ul class="pagination"><li class="paginate_button page-item previous disabled" id="table_container_user_role_coordonator_id5_previous">Previous</li><li class="paginate_button page-item active">1</li><li class="paginate_button page-item next disabled" id="table_container_user_role_coordonator_id5_next">Next</li></ul></div></div></div></div>
It looks like you have the jQuery plug-in Datatables installed in your code base. I would suggest looking at the javascript code and finding the jQuery selector used.
If you only want one table to be enhanced by Datatables then you can write a selector by id, such as:
$(“#table_id_1”).Datatable();
Please post the related javascript code if you can.

Unable to select column with its header through XPath

My HTML
<table id="flex1" cellspacing="0" cellpadding="0" border="0">
<thead>
<tr class="hDiv">
<th width="6%">
<div class="text-left field-sorting asc" rel="IFSC_CODE"> IFSC CODE </div>
</th>
<th width="6%">
<div class="text-left field-sorting " rel="BRANCH_NAME"> BRANCH NAME </div>
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="sorted" width="6%">
<div class="text-left">SACS011151</div>
</td>
<td width="6%">
<div class="text-left">check</div>
</td>
</tr>
<tr class="erow">
<td class="sorted" width="6%">
<div class="text-left">SACS011152</div>
</td>
<td width="6%">
<div class="text-left">Motiram</div>
</td>
</tr>
<tr class="erow">
<td class="sorted" width="6%">
<div class="text-left">SACS011158</div>
</td>
<td width="6%">
<div class="text-left">TESTNAME</div>
</td>
</tr>
</tbody>
</table>
My XPath
//table/tbody/tr/td[count(//table/thead/tr/th[.='BRANCH NAME']/preceding-sibling::th)+4]
Above XPath is Selecting all the column but not selecting its header name 'BRANCH NAME' and I want to select the header name with all its column.Any Idea how to do this?
You can simply use xpath union operator (|) to combine two xpath queries, for example* :
//table/tbody/tr/td[count(//table/thead/tr/th[.='BRANCH NAME']/preceding-sibling::th)+4]
|
//table/thead/tr/th[.='BRANCH NAME']
*: formatted into multiple lines just to make it visible without horizontal scroll

ng-repeat and the mouseover event

this seems like a scope problem, but i am not sure. my goal is to highlight a single row in a table. that implies that any previously highlighted row is returned to an unhighlighted state. the rows are created with the ng-repeat directive, like this:
<div id="myFedContents" style="height:320px" ng-controller="Controller2" class="scroller">
<table border="0" class="span12 table table-condensed" style="margin-left:0px" id="tblData">
<thead>
<tr><th>Year</th><th>Name</th><th>Useful Flag</th></tr>
</thead>
<tbody id="allRows">
<tr ng-repeat="item in itemlist | filter:thisText" ng-style="myStyle"> <td class="span1" valign="top"><a tabindex="-1" href="#">{{item.year}}</a></td>
<td id="{{item.id}}"> <a tabindex="-1" href="#" ng-click="myStyle={'background-color':'#cccccc'};">{{item.name}}</a>
</td> <td>
{{item.usefulflag}
</td> </tr>
</tbody>
</table>
</div>
i have code in a .js file that looks like this:
$("tr").mouseenter(function(){
alert("mouseenter");
});
the row in the table header reacts with the alert, but there is no reaction from the rows created by ng-repeat. how do i correct?
You can actually achieve this effect by using an ng-class in conjuction with ng-mouseenter and ng-mouseleave like so:
<div id="myFedContents" style="height:320px" ng-controller="Controller2" class="scroller">
<table border="0" class="span12 table table-condensed" style="margin-left:0px" id="tblData">
<thead>
<tr>
<th>Year</th>
<th>Name</th>
<th>Useful Flag</th>
</tr>
</thead>
<tbody id="allRows">
<tr ng-repeat="item in itemlist | filter:thisText" ng-style="myStyle" ng-class="highlightclass" ng-mouseenter="highlightclass='highlight'" ng-mouseleave="highlightclass=''">
<td class="span1" valign="top"><a tabindex="-1" href="#">{{item.year}}</a>
</td>
<td id="{{item.id}}"> <a tabindex="-1" href="#" ng-click="myStyle={'background-color':'#cccccc'};">{{item.name}}</a>
</td>
<td>
{{item.usefulflag}
</td>
</tr>
</tbody>
</table>
</div>
In this case you don't need the jquery syntax. If you haven't already you should also read https://stackoverflow.com/a/15012542/281335.

Resources