Get all rows from a dynamic table using Selenium WebDriver - testing

I am working on automating a webpage editing task. The webpage has a dynamic table inside a frame. Each row has five columns. By dynamic table I mean that the rows are loaded dynamically on the web page. At any given point, the number of rows loaded are not more than 22. I can access more rows by moving the scroll bar. The total number of rows in the table is ~450, and I need to read all of them to modify some values in Column 2.
I am currently using Selenium WebDriver to try to read the rows into a List, but can only receive 22 rows at any given time. Here is what I have tried:
IWebElement tableElement = Driver.driverInstance.FindElement(By.XPath(*tableXPath*));
var rowList = tableElement.FindElements(By.TagName("tr"));
Console.WriteLine("Table rows: " + rowList.Count());
Is there any way by which I can read the entire table(450 rows) into a data structure, so I can do in-memory processing on them?
This is how the HTML portion looks like, through FireBug:
<table id="ctl00_MPH_HyperGrid1ContentTable" class="HyperGrid" style="table-layout: fixed; width: 100%;">
<colgroup>
<tbody>
<tr id="ctl00_MPH_HyperGrid1_10" class="" style="height: 37px;">
<tr id="ctl00_MPH_HyperGrid1_11" class="alt" style="height: 37px;">
<tr id="ctl00_MPH_HyperGrid1_12" class="" style="height: 37px;">
<td class="checkable">
<td class="">AntelopeEB</td>
<td class="">CA - Antelope EB</td>
<td class="">SmarterMail</td>
<td class="">User</td>
<td class="">
<td class="loadingCell" colspan="5" style="display:none;">Loading...</td>
</tr>
<tr id="ctl00_MPH_HyperGrid1_13" class="alt" style="height: 37px;">
<tr id="ctl00_MPH_HyperGrid1_14" class="" style="height: 37px;">

"At any given point, the number of rows loaded are not more than 22"
That means only 22 rows can be accessed by selenium and stored into the LIST datastructure as the browser has only 22 rows. You need to trigger an event through SELENIUM to make the remaining data to appear in the browser, so that selenium can retrieve the next 22 tags. You've mentioned that you can access more rows by scrolling, include a function that can trigger the scrolling event. Make use of Thread.sleep(millisecs); if page content loading is slow. Let me know if you need more info, please share the code too

Related

Populating table with object containing an array in vuejs?

I am trying to populate table with an object which contains an array. I am able to successfully do that but I want each task name to have its own row right now they are coming in a single row.
{level_image :"image"level_name:"1"task_name: ["game","taskgame","jenga"]}
<tr v-for="tel in result" :key="tel.level_image" :pey="tel.level_name">
<td>{{tel.level_image}}</td>
<td>{{tel.level_name}}</td>
<td v-for="task in tel.task_name">{{task}}</td>
</tr>
You're missing the obvious: if you want each one to have its own row, you need to put the v-for in a <tr> tag (like you did for result). Exactly how you deal with the <td>s is up in the air, but it might go like this:
<tr v-for="tel in result" :key="tel.level_image" :pey="tel.level_name">
<tr v-for="task in tel.task_name">
<td>{{tel.level_image}}</td>
<td>{{tel.level_name}}</td>
<td>{{task}}</td>
</tr>
</tr>
Or if you mean you want each one to be on a separate line within a table cell, it could be
<tr v-for="tel in result" :key="tel.level_image" :pey="tel.level_name">
<td>{{tel.level_image}}</td>
<td>{{tel.level_name}}</td>
<td><div v-for="task in tel.task_name">{{task}}</div></td>
</tr>
The main idea is that you want the v-for to be associated with the type of tag that creates the entity you want each task in.

Selenium XPath - Ignore element amongst table

I have an issue with selecting a table to be read in Selenium.
I have a table in which there is two 'tr' elements inside the 'thead', and I need to find a way to ignore the first of these.
Here is the code:
<table class="noselect">
<thead>
<tr>
<th> </th>
<th class="number IOL">Interest Rates</th>
<th class="number IO">
</tr>
<tr>
<th>Description</th>
<th class="number">Value</th>
<th class="number">Percentage</th>
</tr>
</thead>
<tbody>
<tr>
<tr class="">
<tr class="">
<tr class="">
<tr>
<tr>
</tbody>
</table>
Using Selenium I will ask it to record the value of a certain row and column . This will then look at the Table element I will give it (hopefully using an XPath I can get working in this case), look at the thead and record the headers of each column. In this case that I am struggling with, the fact there is an extra 'tr' at the top of this table gets in the way of this process.
This is how the element is currently used:
[TableAlias("Detailed table")]
protected virtual IWebElement DetailedTable()
{
return Driver.FindElement(By.XPath("//table[#class='noselect']"));
}
I have tried many different ways which I can't get to work, but the gist of what I've been going for is:
//table[#class='noselect movements']/thead/tr/th[not(text()='Interest Rates')]/../../..
Here I'm stuck on going to the 'tr' element, telling it not to use it then backing out, but that selects it back again - and even that doesn't unselect the whole 'tr' element. It doesn't seem to help (to me) that the 'tr' element I'm trying to remove is blank with no class or defining features.
Is there a way of selecting the entire table except for the first 'tr' element in 'thead' as one element?
combine two xpathes. The 1st xpath take thead without the 1st tr and the 2nd tbody
//table/thead/tr[not(position()=1)] | //table/tbody
In your function that processes the THEAD tag, get the collection of TRs and start with [1] (skipping [0]) and process the rest.

Aligning two tables with different number of rows inside a parent table

Inside a parent table, I have table1(with 3 rows) and table2(with 2 rows). I need table2 to align at the top with table1 and right now its centering table2. I know about divs and float but this page is getting sent through a mail server and it renders the page all weird and I have to use tables.
I tried to post some images of my code but its saying I need at least 10 reputations to post images?
try adding valign="top" on your parent table td elements as the default vertical alignment is center or middle for td elements
<table id="parent">
<tr>
<td valign="top">
<table id="table1"></table>
</td>
<td valign="top">
<table id="table2"></table>
</td>
</tr>
</table>

rowsPerPage not working with dojox.grid.DataGrid

Currently i am getting 100 Records from my Servlet .
I want to display only 20 Records per page , i am using dojox.grid.DataGrid , but still its displaying all the 100 Records
Please help .
<body class=" claro ">
<span dojoType="dojo.data.ItemFileReadStore" jsId="store1" url="http://localhost:8080/Game/servlet/Hi"></span>
<table dojoType="dojox.grid.DataGrid" store="store1" rowsPerPage="20" rowSelector="20px"
style="width: 100%; height: 500px;">
<thead>
<tr>
<th width="150px" field="name">Namer3</th>
<th width="150px" field="dept">Deptr3</th>
</tr>
</thead>
</table>
</body>
I would suggest you start using a QueryReadStore, and change your servlet to respect the start and count parameters that are part of the post. This will allow the grid to fetch the rows 1-20, then 21-40 when the user scrolls down, and so forth.
If you're looking to tell the grid to render only 20 rows at a time and wait for a scroll event for the others, that should already be handled. I would suggest you double check your grid. Initially 20 rows should be rendered with values, and the later ones should just have "..." inside all the values until scrolled into view.

XPath Text Search/Sibling Selection

This question might be a little specific but the test program im writing uses XPath to find the data i need in HTML. This piece of HTML(found here) is what im trying to parse.
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="textSm" align="right">1. </td> <!-- Location of the number is here -->
<td align="left" nowrap>
P Sandoval <!-- Player location is here of the number is here -->
</td>
</tr>
</table>
My goal is to find the name of the person by using the number that corresponds to him to find him. This requires me to find a node by the specific text contained in "td class="textSm" align="right">1. </td>" and then find the sibling of that node "<td align="left" nowrap>" then find the child of that sibling "P Sandoval" to get the desired result. I was wondering what kind of query I could use to find this. Any help is very much appreciated.
Use:
table/tr/td[starts-with(., '1.')]/following-sibling::td/a
This assumes that the context (current node) against which the XPath expression above is evaluated, is the parent of table.
//tr[td = "1"]/td[2]/a
For all TRs which have a TD equal to '1', give from the second child TD the A element.