How to create resuable methods for Tables in Selenium Webdriver - xpath

I need to work with tables by using reusable method for different table. We have two different types of tables as below
<div id="grid">
<div class="header">
<table>
<thead>
<tr>
<tr>
<div id="grid">
<div class="header">
<table>
<tbody>
<tr>
how can i write a common method for these two.
i would like to have some thing like..
//div[#id='Grid']/div/table/tbody or thead.
i would like to just pass the table id like
//div[#id='"+tableId+"']/div/table/tbody or thead

I believe you can use use '|' for 'or'
//div[#id='"+tableId+"']/div/table/tbody|//div[#id='"+tableId+"']/div/table/thead

Related

How to select different registers in a table in a laravel view?

Here´s the thing. I have a view to show different students in a table. I`d like to select some of them, and send that to a method in my controller.
Here is my table in the view:
<body style="background-color:#DEF5E5;">
#auth
<h1>Añade amigos de {{$student->name}}</h1>
<table class="table">
<thead style="background-color:#9ED5C5">
<tr>
<th>Nombre</th>
<th>Apellidos</th>
<th>Edad</th>
<th>Opciones</th>
</tr>
</thead>
<tbody>
#foreach($students as $student)
<tr>
<td>{{$student->name}}</td>
<td>{{$student->surname}}</td>
<td>{{$student->age}}</td>
<td>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
#endauth
#guest
<div class="container">
<h1>Debes iniciar sesión</h1>
#endguest
</body>
</html>
I'd like to select some of the registers, store them in and array or something like that and send that array to a method in my controller, but I don`t know how to select various rows and send them. Thank you.

Sorting multiples values on same td using datatable yadcf

I'm trying to sort several values ​​in a td, I would like to know a more effective way, I used (yadcf) but I couldn't get a property that looks for the value of each tag
Example
Order by:Tag 1 (show taghead name) on click sort tag values
Tag 2
tag 3
datatable:
<table>
<thead>
<tr>
<td>col1</td>
<td>col 2</td>
</tr>
<thead>
<tbody>
<tr>
<td>value</td>
<td>
<div class="tag1">
<div class="taghead">tag1</div>
<div>value</div>
</div>
<div class="tag2">
<div class="taghead">tag2</div>
<div>value</div>
</div>
<div class="tag3">
<div class="taghead">tag3</div>
<div>value</div>
</div>
</td>
</tr>
<tbody>
</table>

Vue JS - <tr> , <td> elements not getting rendered when passed to table component

I have registered a single file table component using vue.js as:
<template>
<div>
<table class="table border">
<thead>
<tr>
<td>header 1</td>
<td>header 2</td>
</tr>
</thead>
<tbody>
<slot></slot>
</tbody>
</table>
</div>
</template>
<script>
export default {};
</script>
<style></style>
I want to use it as a representational component. When I try to pass tr and td elements to it in Laravel blade like:
<table-component>
<tr>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
</tr>
</table-component>
how I registered the component:
Vue.component(
"table-component",
require("./components/admin/TableComponent.vue").default
);
everything get rendered except row and data elements and the table gets out of form. here`s table content and elements after getting rendered in browser:
table elements in browser picture
I have read online articles and searched through Q/As but couldn`t find anything.
It's mentioned in the official docs DOM Template Parsing Caveats
Also refer this issue for more clarity https://github.com/vuejs/Discussion/issues/204

how to get table rows which is nested in other tables using xpath in scrapy spiders

How to get the table rows which is nested in other tables and form tag.
I tried few codes but doesn't seem to work.
I have used the below python code but not able to get anything
def parse(self, response):
t = response.xpath('//table[#class="DataGrid"]/tbody/tr')
for tr_obj in enumerate(t):
print(tr_obj.xpath('td[1]/text()').extract_first())
Below is html code and in this I need to get table which has the class name as gridTable
<html>
<body>
<table></table>
<table>
<tbody>
<tr>
<td>
<span></span>
<script></script>
<form>
<table class="dPage1">
<tbody>
<tr></tr>
<tr>
<td>
<table>
<tbody>
<tr>
<td>
<table class="gridTable">
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</form>
</td>
</tr>
</tbody>
</table>
</body>
</html>
Solution
for tr_obj in enumerate(response.xpath('//table[#class="DataGrid"]/tr')):
print(tr_obj.xpath('td[1]/text()').extract_first())
You can choose which tags to follow in xpath by specifying the tag in brackets.
For your example it would be:
//table[#class="gridTable"]/...
It is recommended that you must not use tbody in your XPath statements in the scrapy documentation.
So try without them and/or try to circumvent them by using /*/ or //.
Try something like:
def parse(self, response):
# Get a Selector list for all rows
sel_rows = response.xpath('//table[#class="DataGrid"]/tr')
# loop over row selectors ...
for sel_row in sel_rows:
print(sel_row.xpath('td[1]/text()').extract_first())

How do you implement a generic CRUD grid using knockout.js?

I have a very nice grid with Create, Retrieve, Edit and Delete functionality. I am using knockout.js on the client and WebAPI on the back end.
I would like to extend this to a number of different objects. Essentially I have a List<T> where T is an MVC view model and the knockout view and view model should be able to work out what they should look like based on T.
Does anyone know of a simple way to display any viewmodel (with specific controls for editing based on the viewmodel itself - eg datepicker for dates, input for string, drop downs etc) in a grid format and have generic CRUD functions.
Below is an example of the exiting HTML I am using (for a specific object):
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Value Date</th>
<th>Position Date</th>
<th>Book</th>
<th>Currency</th>
<th>Currency Base</th>
<th>Amount1</th>
<th>Amount2</th>
<th>Position Type</th>
<th style="width: 100px; text-align:right;" />
</tr>
</thead>
<tbody data-bind=" template:{name:templateToUse, foreach: pagedList }"></tbody>
</table>
and the templates look like this:
<script id="itemsTmpl" type="text/html">
<tr>
<td data-bind="text: valueDate.formattedDate"></td>
<td data-bind="text: positionDate.formattedDate"></td>
<td data-bind="text: book"></td>
<td data-bind="text: currency"></td>
<td data-bind="text: currencyBase"></td>
<td data-bind="text: amount1"></td>
<td data-bind="text: amount2"></td>
<td data-bind="text: positionType"></td>
<td class="buttons">
<a class="btn" data-bind="click: $root.edit" href="#" title="edit"><i class="icon-pencil"></i></a>
<a class="btn" data-bind="click: $root.remove" href="#" title="remove"><i class="icon-trash"></i></a>
</td>
</tr>
</script>
<script id="editTmpl" type="text/html">
<tr>
<td><input data-bind="datepicker: valueDate.formattedDate, datepickerOptions: { dateFormat: 'yy/mm/dd' }"/></td>
<td><input data-bind="datepicker: positionDate.formattedDate, datepickerOptions: { dateFormat: 'yy/mm/dd' }"/></td>
<td><input data-bind="value: book"/></td>
<td><input data-bind="value: currency"/></td>
<td><input data-bind="value: currencyBase"/></td>
<td><input data-bind="value: amount1"/></td>
<td><input data-bind="value: amount2"/></td>
<td><input data-bind="value: positionType"/></td>
<td class="buttons">
<a class="btn btn-success" data-bind="click: $root.save" href="#" title="save"><i class="icon-ok"></i></a>
<a class="btn" data-bind="click: $root.cancel" href="#" title="cancel"><i class="icon-remove"></i></a>
</td>
</tr>
</script>
I would like the View as well as the View Model to be generic and not "hard-coded" as above. I am sure someone else must have done something like this.
One solution would be that:
AJAX call gets a list of JSON viewmodels
If list is empty then do not display anything
If list has items, pick first item and go through properties
Start constructing the view on the client by looping through proprties
Append the string as a DOM element to the main DIV
Wireup knockout
There are problems with this approach. What if a property is null for the first object but exists in another? If so we do not setup the element for it.
A better option is to use content negotiation to get a dedicated template:
So GET /api/customers will return customers but if you request text/knockout-template+html then you get back a knockout template as string and then you append to DIV and wireup knockout. So server can generate template using reflection or customise for some models.

Resources