PHPTAL and specific table - html-table

I have to create specific table in PHPTAL.
I have array like that:
$tab = array('item1', 'item2', 'item3', 'item4');
Final table should be look like that:
<table>
<tr>
<td>Item1</td>
<td>Item2</td>
</tr>
<tr>
<td>Item3</td>
<td>Item4</td>
</tr>
</table>
So I was trying use tal:condition width "repeat/item/odd" and "repeat/item/even" to fit < tr > tag in right place, but it not working that I want to.
Have you any ideas?

<tr tal:repeat="row php:array_chunk(tab, 2)">

Related

Get specific value based on column & row name from dynamic Web table in which columns & rows position also dynamic

I have to print a specific value based on column and row names.
Bt the problem is that columns position and rows position changes every time. And table data is dynamic, values are changing continuously. All the values are not constantmy dynamic web table is. and i want specific value of month April in year 2001.
Here is the sample table based on the attached screenshot.
<html>
<table id='table1' border=" 1px solid black">
<tr>
<th>Month/Year</th>
<th>2003</th>
<th>2004</th>
<th>2001</th>
<th>2005</th>
<th>2002</th>
</tr>
<tr>
<td>May</td>
<td>122</td>
<td>84</td>
<td>7777</td>
<td>12</td>
<td>122</td>
</tr>
<tr>
<td>Feb</td>
<td>45</td>
<td>445</td>
<td>565</td>
<td>222</td>
<td>122</td>
</tr>
<tr>
<td>April</td>
<td>3556</td>
<td>212</td>
<td>21</td>
<td>1546</td>
<td>855</td>
</tr>
</table>
<span>-----------------------------------------------</span>
<table id='table2' border=" 1px solid black">
<tr>
<th>Month/Year</th>
<th>2002</th>
<th>2001</th>
<th>2003</th>
<th>2004</th>
<th>2005</th>
</tr>
<tr>
<td>April</td>
<td>120</td>
<td>243</td>
<td>221</td>
<td>21</td>
<td>65</td>
</tr>
<tr>
<td>May</td>
<td>96</td>
<td>146</td>
<td>454</td>
<td>452</td>
<td>4566</td>
</tr>
<tr>
<td>March</td>
<td>788</td>
<td>139</td>
<td>10</td>
<td>1001</td>
<td>013</td>
</tr>
<tr>
<td>Feb</td>
<td>552</td>
<td>1245</td>
<td>545</td>
<td>41</td>
<td>41</td>
</tr>
</table>
</html>
Below is the xpath to get the value of "April/2001" from table 1.
//table[#id='table1']//td[position()=count(//th[normalize-space(.)='Month/Year']/preceding-sibling::th)+1 and normalize-space(.)='April']/ancestor::tr//td[position()=count(//table[#id='table1']//th[normalize-space(.)='2001']/preceding-sibling::th)+1]
And xpath to get the value of "April/2001" from table 2.
//table[#id='table2']//td[position()=count(//th[normalize-space(.)='Month/Year']/preceding-sibling::th)+1 and normalize-space(.)='April']/ancestor::tr//td[position()=count(//table[#id='table2']//th[normalize-space(.)='2001']/preceding-sibling::th)+1]
The only difference between the 2 xpaths' above is table id **//table[#id='tableX**. Please update the table locator as per your application values.
Let me know if this is helpful.

identify the content of xml using header value in sql

DECLARE #xml xml=' <?xml version="1.0" encoding="UTF-8"?><text>
<table>
<thead>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
<th>e</th>
<th>f</th>
</tr>
</thead>
<tbody>
<tr>
<td>testa1</td>
<td>testb1</td>
<td>testc1</td>
<td>testd1</td>
<td>teste1</td>
<td>testf1</td>
</tr>
<tr>
<td>testa1</td>
<td>testb1</td>
<td>testc1</td>
<td>testd1</td>
<td>teste1</td>
<td>testf1</td>
</tr>
</tbody>
</table>
</text>'
SELECT
T.c.value('(tbody/tr/td)[1]','VARCHAR(100)') AS a
FROM
#xml.nodes('text/table[thead[tr[th="b"]]]') AS t(c)
This query selects only the first body contents from xml.
Here I want to select only the values under header b
Modifying the xpath as follows will do it:
SELECT T.c.value('/text/table/tbody/tr/td[position()=2]','VARCHAR(100)') AS a
Explanation:
Selects the second td element among a list of siblings.
Note:
Combine that with this SO answer to get:
SELECT T.c.value('/text/table/tbody/tr/td[position() = count(/text/table/tbody/tr/th[text() = "b"]/preceding-sibling::*)+1]','VARCHAR(100)') AS a

relation between original columns indexes and columns indexes after sorting in datatables

I need to find relation between original columns indexes and columns indexes after sorting in datatables .
say we have an ordinary html table :
<table id="namesTable">
<thead>
<th>First Name</th>
<th>Last Name</th>
</thead>
<tbody>
<tr>
<td>Jim</td>
<td>Andrew</td>
</tr>
<tr>
<td>Pedro</td>
<td>Rodriguez</td>
</tr>
<tr>
<td>Manau</td>
<td>Lara</td>
</tr>
</tbody>
</table>
after calling :
$('#namesTable').DataTable(
'order' : [[0 , 'Desc']]
);
is there any way to have like a dictionnary that says that index 0 is now2 and 1 is now 0 and 2 is now 1 after ordering ?
any help is welcome !
dataTables row().index() or rows().indexes() returns the original index, eg how the rows are ordered in the underlying HTML. To get the row index from the example above :
$('#namesTable tbody').on('click', 'tr', function () {
alert(table.row(this).index());
});
demo -> http://jsfiddle.net/d6tcLtha/

Selenium compare stored Text with NOT or != operator

i'm trying to compare the content of two variables in order to return if variable1 != variable2.
I found some different examples, how to compare variables, but not how to use this with an operator.
First of all, i store text, wait 5 minutes and store text again. If the text is different, so the testis passed.
<tr>
<td>storeText</td>
<td>id=newsdiv_1</td>
<td>newsBox1</td>
</tr>
<!--wait 6 min for ajax update-->
<tr>
<td>pause</td>
<td>360000</td>
<td></td>
</tr>
<tr>
<td>storeText</td>
<td>id=newsdiv_1</td>
<td>newsBox2</td>
</tr>
<tr>
<td>verifyExpression</td>
<td>${newsBox1}</td>
<td>regexp=!(${newsBox2})</td>
</tr>
verifyExpressionworks perfect in comparing if 2 variables are equal.
But the last test should work like this: if newsBox1!=newsBox2 than return true
You can do a verifyNotExpression, which is basically a not of the verifyExpression:
<tr>
<td>verifyNotExpression</td>
<td>${newsBox1}</td>
<td>${newsBox2}</td>
</tr>

How do I retrieve the text in a table column using Selenium RC?

I have a table that looks like the following:
<table class="theClass">
<tr>
<td class="anotherClass"><strong>Label1:</strong></td>
<td colspan="3">Value1a<br/>Value1b<br/>Value1c</td>
</tr>
<tr>
<td class="anotherClass"><strong>Label2:</strong></td>
<td colspan="3">Value2a<br/>Value2b<br/>Value2c</td>
</tr>
<tr>
<td class="anotherClass"><strong>Label3:</strong></td>
<td colspan="3">Value3a<br/>Value3b<br/>Value3c</td>
</tr>
</table>
How can I use Selenium RC to retrieve Value1a, Value1b, and Value1c ? Can I use selenium.getText(...) or storeText(...)? If so, what is the proper xpath I should use? Please assume that the table cannot be changed. Thanks!
it would be
string value1 = selenium.getTable("table.1.2");
string value2 = selenium.getTable("table.2.2");
and so on.
The help text for getTable is
getTable(tableCellAddress) Arguments:
tableCellAddress - a cell
address, e.g. "foo.1.4"
Returns:
the text from the specified cell
Gets the text from a cell of a table. The cellAddress syntax
tableLocator.row.column, where row and
column start at 0.
Check this,
int i =1;
while(selenium.isElementPresent("//table/tbody/tr["+i+"]/td[2]")){
System.out.println(selenium.getText("//table/tbody/tr["+i+"]/td[2]"));
i++;
}
Result will contain all the values listed.Hope it helps!!!
String value1 = selenium.getText("//tr[1]/td[1]/strong[contains(text(), Label1:')]/../../td[2]");
selenium.gettable(xpath)