First matching element using CSSSelector - selenium-webdriver

So, I am trying to get the test of the column Title or Names or DateTime
I'm trying to get the test td element and I have tried the following using CSSSelector:
div#body-inner div#ctl00_ContentPlaceHolder1_Control1_pnlList div table#ctl00_ContentPlaceHolder1_Control1_gv.gv tbody tr.item td:nth-child(4)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head id="ctl00_PageHead">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Employee</title>
<body id="ctl00_PageBody">
<form name="aspnetForm">
<div>
</div>
<div>
</div>
<table class="global-table" cellpadding="0" cellspacing="0">
<tr class="body">
<td>
<div id="body">
<div id="body-inner">
<h1>
Employee Information</h1>
<div id="ctl00_ContentPlaceHolder1_Control1_pnlList" style="width: 100%;">
<div class='filter'>
</div>
<div>
<table class="gv" cellspacing="0" border="0" id="ctl00_ContentPlaceHolder1_Control1_gv" style="border-collapse: collapse;">
<tr class="header">
<th class=" nolink" scope="col">
</th>
<th scope="col">
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Sort$Phone')">
Phone</a>
</th>
<th class=" sorted-desc" scope="col">
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Sort$Title')">
Title</a>
</th>
<th scope="col">
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Sort$SubTitle')">
SubTitle</a>
</th>
<th scope="col">
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Sort$Names')">
Names</a>
</th>
<th scope="col">
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Sort$Names')">
Enames</a>
</th>
<th scope="col">
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Sort$Active')">
Active</a>
</th>
<th scope="col">
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Sort$DateTime')">
DateTime</a>
</th>
</tr>
<tr class="item">
<td align="center">
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Select$0')">
Edit</a>
</td>
<td align="center" style="width: 15px;">
</td>
<td>
Test
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
8/23/2011
</td>
</tr>
<tr class="altItem">
<td align="center">
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Select$1')">
Edit</a>
</td>
<td align="center" style="width: 15px;">
</td>
<td>
Test1
</td>
<td>
1
</td>
<td>
Employee
</td>
<td>
</td>
<td>
</td>
<td>
7/31/2014
</td>
</tr>
<tr class="item">
<td align="center">
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Select$2')">
Edit</a>
</td>
<td align="center" style="width: 15px;">
</td>
<td>
Test2</td>
<td>
111
</td>
<td>
Employer
</td>
<td>
</td>
<td>
</td>
<td>
7/31/2013
</td>
</tr>
<tr class="altItem">
<td align="center">
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Select$3')">
Edit</a>
</td>
<td align="center" style="width: 15px;">
</td>
<td>
Test3</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
8/23/2011
</td>
</tr>
<tr class="item">
<td align="center">
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Select$4')">
Edit</a>
</td>
<td align="center" style="width: 15px;">
</td>
<td>
Test4</td>
<td>
2
</td>
<td>
Employer
</td>
<td>
</td>
<td>
</td>
<td>
7/31/2012
</td>
</tr>
<tr class="altItem">
<td align="center">
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Select$5')">
Edit</a>
</td>
<td align="center" style="width: 15px;">
</td>
<td>
Test5</td>
<td>
3
</td>
<td>
Employer
</td>
<td>
</td>
<td>
</td>
<td>
7/31/2012
</td>
</tr>
<tr class="item">
<td align="center">
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Control1$gv','Select$6')">
Edit</a>
</td>
<td align="center" style="width: 15px;">
</td>
<td>
Test6
</td>
<td>
a
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
7/20/2012
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr class="footer">
<td>
</td>
</tr>
</table>
</form>
</body>
</html>
the result I am getting is all the matching elements but how can I get only the td which is test?
<td >
test
</td>
<td >
DEMO TEST OCT 25
</td>
<td class="firefinder-match">
DEMO TEST OCT 25
</td>
<td >
DEMO TEST OCT 25
</td>
<td >
DEMO TEST OCT 25
</td>
<td >
DEMO TEST OCT 25
</td>

The issue lies with tr.item. There are multiple rows with that class and you are selecting all of them. Be more specific by using the first-child pseudo class so it will only select the first tr.item and not all of them.

Here is how I able to get:
table#ctl00_ContentPlaceHolder1_Control1_gv.gv tbody tr.item:nth-child(3) > td:nth-of-type(3)

Related

Search on bootstrap table with expanding rows

I have a bootstrap table with expanding rows. Each row can expand into multiple rows, and those can too expand in multiple rows (3 levels in total).
The search does find items on the 3rd level but it doesn't display them correctly.
This is an example code on codepen.
https://codepen.io/anon/pen/gGOOBz
My HTML code is:
<table st-table="displayedCollection" st-safe-src="domains" class="table table-condensed" style="border-collapse:collapse;">
<thead>
<tr>
<th st-sort="name">Domains</th>
</tr>
<tr>
<th colspan="5"><input st-search="" class="form-control" placeholder="Search ..." type="text" /></th>
</tr>
</thead>
<tbody ng-cloak>
<tr ng-repeat-start="row in displayedCollection">
<td id="package1-{{$index}}" class="accordion-toggle data-exists cursor-pointer" data-toggle="collapse" data-parent="#OrderPackages-{{$index}}" data-target=".packageDetails1-{{$index}}">{{row.name}}
</td>
</tr>
<tr ng-repeat-end>
<td id="package2-{{$index}}" colspan="3">
<div class="accordion-body collapse packageDetails1-{{$index}} + 1">
<table st-table="beansCollection" st-safe-src="types" class="table table-condensed" style="border-collapse:collapse;">
<!--<thead>
<tr>
<th st-sort="name">Types</th>
</tr>
</thead>-->
<tbody>
<tr ng-repeat-start="beanType in row.beans">
<td id="type1-{{$index}}" class="accordion-toggle" data-toggle="collapse" data-parent="#typePackages-{{$index}}" data-target=".typesDetails1-{{$index}}">
{{beanType.name}}
</td>
<td align="right">
<button ng-click="getBeanName(beanType.name, null, beanType)" data-toggle="modal" data-target="#myModal" type="button" class="btn btn-default" ng-if="showButton(beanType.beans)">
Display
</button>
</td>
</tr>
<!---->
<tr ng-repeat-end ng-visible="false">
<td id="typeId2-{{$index}}" colspan="3">
<div class="accordion-body collapse typesDetails1-{{$index}} + 1">
<table class="table table-condensed">
<tbody>
<tr ng-repeat="leafBean in beanType.beans">
<td>
{{leafBean.name}}
</td>
<td align="right">
<button ng-click="getBeanName(beanType.name, leafBean.name, leafBean)" data-toggle="modal" data-target="#myModal" type="button" class="btn btn-default">Display</button>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
I want that when I search something under a certain row it would be displayed with the row above already expanded.
PHOTO:
Say I want to search for TBLEXCHANGEMEMBERSHIPS which is on the 3rd level.
When I input it into the search bar, it finds it but doesn't display it correctly.
What should I do?

Incompatibility between AngularJS and Firefox

My tables do not appear in Firefox. I saw that there is a compatibility problem with Firefox with AngularJS, what can I do?
Follow the code.
<table class="displayTagCss">
<thead>
<th style="width: 50px;"> </th>
<th style="width: 50px;">Ordem</th>
<th>Alertas</th>
<th>Proposição</th>
<th>Situação</th>
<th style="width: 50px;"> </th>
</thead>
<tbody>
<tr ng-repeat="proposicao in gruposSentencas['<c:out value='${grupo.idSentencaDePesquisa}' />']">
<td style="text-align: center;">
<img alt="Subir" title="Subir" ng-show="!$first" src="<html:rewrite page='/imagens/botao_subir.gif' />" ng-click="subirProposicao('<c:out value='${grupo.idSentencaDePesquisa}' />', $index)" />
<img alt="Descer" title="Descer" ng-show="!$last" src="<html:rewrite page='/imagens/botao_descer.gif' />" ng-click="descerProposicao('<c:out value='${grupo.idSentencaDePesquisa}' />', $index)" />
</td>
<td style="text-align: center;">{{$index+1 }}</td>
<td>
<div class="hover" ng-if="(proposicao.alertas.length > 0) || proposicao.haPendencia">
<img src="<html:rewrite page='/imagens/gfx/warning.png'/>" />
<div class="appear">
<ul>
<li class="alerta_proposicao" ng-repeat="alerta in proposicao.alertas">{{ alerta }}</li>
<li class="alerta_proposicao" ng-if="proposicao.haPendencia"><span>Observações de fase: </span>{{proposicao.textoObservacao}}</li>
</ul>
</div>
</div>
</td>
<td>{{ proposicao.identificadorDaProposicao }}</td>
<td>{{ proposicao.situacao }}</td>
<td style="text-align: center;"><img src="<html:rewrite page='/imagens/chk_off.png' />" ng-click="removerProposicao('<c:out value='${grupo.idSentencaDePesquisa}' />', $index)" alt="Excluir" title="Excluir" /></td>
</tr>
</tbody>
</table>
The 'thead' works, but the 'tbody' does not appear in Firefox.

how to loop through a table in selenium?

I am new to selenium and I have this question where I need to loop through a table and get the values in that table
<table>
<tr>
<td style="width:5px">
</td>
<td>
<table class="reportTable" id="Allocations">
<tbody>
<tr class="table_header">
<td style="width:5px;">
<img class="HideImage" src="Images/minus.gif" alt="Hide Details">
</td>
<td style="width:33%">
Channel of Trade</td>
<td style="width:33%">
PILOT TRAVEL CENTE-122194-W/S - UNB Contract</td>
<td style="width:33%">
<span id="TruckLoading_10142602_Info" style="COLOR: white;text-decoration:underline;cursor:pointer">
Trucks loading - 0</span>
</td>
</tr>
<tr>
<td style="width:5px;">
</td>
<td colspan="3">
<table rules="rows" class="reportTable" font-family="Tahoma" pagerstyle-visible="False" id="TerminalGrid" border="1">
<tbody>
<tr class="productlabel2" align="left">
<td scope="col" style="width:5px;">
</td>
<td>
Product Details</td>
</tr>
<tr class="hdr2">
<td scope="col" style="width:5px;">
</td>
<td scope="col">
Fuel Type</td>
</tr>
<tr class="FuelTypeHeader">
<td style="width:5px;border:none" onclick="ShowHideDetails(this)">
<img class="HideImage" src="Images/minus.gif" alt="Hide Details" id="Fuel_Img">
</td>
<td style="border-left:none;border-right:none; padding-left:3px">
<table id="C_V" style="width:100%;border-collapse:collapse; border:none; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;">
<tbody>
<tr>
<td style="width:20em;">
<span>
DSL - LSD/ULSD</span>
</td>
<td style="width:60em;">
<span id="CVSpan">
<span style="margin-right:10px">
<span style="float:left;padding-top:3px">
Currently:</span>
<span style="float:left;width:6em;padding-top:2px; margin-left:5px; margin-right:5px;margin-top:2px;padding-bottom:2px; text-align:center; background-color:#00FF00;">
Available</span>
<span style="float:left; padding-top:3px">
<b>
30,839</b>
gallons remaining until Mon 8/1/2016 12:00:00 AM CDT</span>
</span>
</span>
</td>
<td align="right">
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr style="">
<td style="width:5px;">
</td>
<td>
<table id="ProdDetails" rules="all" pagerstyle-visible="False" style="width: 100%" border="1">
<tbody>
<tr class="table_header2">
<th scope="col">
Nominated Volume</th>
<th scope="col">
Allocation Period</th>
<th scope="col">
Allocation %</th>
<th scope="col">
Allocation Start Amt</th>
<th scope="col">
Allocation Lifted</th>
<th scope="col">
Allocation Remaining</th>
<th scope="col">
GPO Allowance</th>
<th scope="col" class="center width8em">
GPO Remaining</th>
<th scope="col">
Category Status</th>
<th scope="col">
Ratability Status</th>
<th scope="col">
Next Scheduled Refresh Date</th>
<th scope="col">
Reference ID</th>
</tr>
<tr class="tablerow2">
<td class="right width8em">
41,118</td>
<td class="center width10em">
Daily</td>
<td class="right">
75%</td>
<td class="right">
30,839</td>
<td class="right">
0</td>
<td class="right">
30,839</td>
<td class="right">
0</td>
<td class="right width8em bold" id="GPO_Rmd">
0
</td>
<td class="center" style="background-color:#00FF00;">
Available</td>
<td class="center" style="background-color:#0099CC;">
Below Trend</td>
<td class="center width20em">
8/1/2016 12:00:00 AM CDT</td>
<td class="center width20emWordWrap">
DSL - LSD/ULSD</td>
</tr>
<tr class="tablerow2">
<td class="right width8em">
287,826</td>
<td class="center width10em">
Weekly</td>
<td class="right">
125%</td>
<td class="right">
359,783</td>
<td class="right">
114,083</td>
<td class="right">
245,700</td>
<td class="right">
0</td>
<td class="right width8em bold" id="GPO_Rmd">
0
</td>
<td class="center" style="background-color:#00FF00;">
Available</td>
<td class="center" style="background-color:#0099CC;">
Below Trend</td>
<td class="center width20em">
8/4/2016 12:00:00 AM CDT</td>
<td class="center width20emWordWrap">
DSL - LSD/ULSD</td>
</tr>
<tr class="tablerow2">
<td class="right width8em">
1,233,540</td>
<td class="center width10em">
Monthly</td>
<td class="right">
115%</td>
<td class="right">
1,418,571</td>
<td class="right">
1,361,264</td>
<td class="right">
57,307</td>
<td class="right">
0</td>
<td class="right width8em bold" id="GPO_Rmd">
0
</td>
<td class="center" style="background-color:#FFFF00;">
Low</td>
<td class="center" style="background-color:#00CC00;">
On Track</td>
<td class="center width20em">
8/1/2016 12:00:00 AM CDT</td>
<td class="center width20emWordWrap">
DSL - LSD/ULSD</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr id="GPO_Row">
<td style="width:5px;">
</td>
<td>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr class="table_header">
<td style="width:5px;" onclick="ShowHideDetails(this)">
<img class="HideImage" src="Images/minus.gif" alt="Hide Details">
</td>
<td style="width:33%">
Channel of Trade</td>
<td style="width:33%">
PILOT TRAVEL CENTE-122194-W/S - UNB Fwrd Cont</td>
<td style="width:33%">
<span id="TruckLoading_17049566_Info" style="COLOR: white;text-decoration:underline;cursor:pointer" onclick="GetTruckLoadingInformationJS(this,17049566);">
Trucks loading - 0</span>
</td>
</tr>
<tr>
<td style="width:5px;">
</td>
<td colspan="3">
<table rules="rows" class="reportTable" font-family="Tahoma" pagerstyle-visible="False" id="TerminalGrid" border="1">
<tbody>
<tr class="productlabel2" align="left">
<td scope="col" style="width:5px;">
</td>
<td>
Product Details</td>
</tr>
<tr class="hdr2">
<td scope="col" style="width:5px;">
</td>
<td scope="col">
Fuel Type</td>
</tr>
<tr class="FuelTypeHeader">
<td style="width:5px;border:none" onclick="ShowHideDetails(this)">
<img class="HideImage" src="Images/minus.gif" alt="Hide Details" id="Fuel_Img">
</td>
<td style="border-left:none;border-right:none; padding-left:3px">
<table id="C_V" style="width:100%;border-collapse:collapse; border:none; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;">
<tbody>
<tr>
<td style="width:20em;">
<span>
DSL - LSD/ULSD</span>
</td>
<td style="width:60em;">
<span id="CVSpan">
<span style="margin-right:10px">
<span style="float:left;padding-top:3px">
Currently:</span>
<span style="float:left;width:6em;padding-top:2px; margin-left:5px; margin-right:5px;margin-top:2px;padding-bottom:2px; text-align:center; background-color:#FF0000;">
Out</span>
<span style="float:left; padding-top:3px">
<b>
0</b>
gallons remaining until Mon 8/1/2016 12:00:00 AM CDT</span>
</span>
</span>
</td>
<td align="right">
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr style="">
<td style="width:5px;">
</td>
<td>
<table id="ProdDetails" rules="all" pagerstyle-visible="False" style="width: 100%" border="1">
<tbody>
<tr class="table_header2">
<th scope="col">
Nominated Volume</th>
<th scope="col">
Allocation Period</th>
<th scope="col">
Allocation %</th>
<th scope="col">
Allocation Start Amt</th>
<th scope="col">
Allocation Lifted</th>
<th scope="col">
Allocation Remaining</th>
<th scope="col">
GPO Allowance</th>
<th scope="col" class="center width8em">
GPO Remaining</th>
<th scope="col">
Category Status</th>
<th scope="col">
Ratability Status</th>
<th scope="col">
Next Scheduled Refresh Date</th>
<th scope="col">
Reference ID</th>
</tr>
<tr class="tablerow2">
<td class="right width8em">
0</td>
<td class="center width10em">
Custom 1 day(s)</td>
<td class="right">
100%</td>
<td class="right">
0</td>
<td class="right">
0</td>
<td class="right">
0</td>
<td class="right">
0</td>
<td class="right width8em bold" id="GPO_Rmd">
0
</td>
<td class="center" style="background-color:#FF0000;">
Out</td>
<td class="center" style="background-color:#0099CC;">
Below Trend</td>
<td class="center width20em">
8/1/2016 12:00:00 AM CDT</td>
<td class="center width20emWordWrap">
MERC-DSL</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr id="GPO_Row">
<td style="width:5px;">
</td>
<td>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
I wanted to know how to loop the table so i can get a contracts that's the " PILOT TRAVEL CENTE-122194-W/S - UNB Contract","PILOT TRAVEL CENTE-122194-W/S - UNB Fwrd Cont" and "UNB Spot" along with the data of the table also.
Thanks in advance.
Ok you didn't say nothing about the language you use so i will give you example in C#
//Init table element (in this case by tag name but better chose by id or Name)
IWebElement tableElement = driver.FindElement(By.TagName("table"));
//Init TR elements from table we found into list
IList<IWebElement> trCollection = tableElement.FindElements(By.TagName("tr"));
//define TD elements collection.
IList<IWebElement> tdCollection;
//loop every row in the table and init the columns to list
foreach(IWebElement element in trCollection)
{
tdCollection = element.FindElements(By.TagName("td"));
//now in the List you have all the columns of the row
string column1 = tdCollection[0].Text;
string column2 = tdCollection[1].Text;
...
}
if you use other language just change the syntax the logic is the same.

Update row in Angular JS

I am submiting a form using Angular JS and Web service. Here is code-
<table>
<tr>
<td style="text-align: right;">Name :
</td>
<td>
<input type="text" id="txtEmpName" ng-model="EmpName" />
</td>
</tr>
<tr>
<td style="text-align: right;">Age :
</td>
<td>
<input type="text" id="txtEmpAge" ng-model="EmpAge" />
</td>
</tr>
<tr>
<td style="text-align: right;">City :
</td>
<td>
<input type="text" id="txtEmpCity" ng-model="EmpCity" />
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<input type="submit" id="btnSubmit" value="Submit" />
</td>
</tr>
</table>
I want to make these text boxes reusable on Edit i.e. on edit click corresponding rows item must be filled and the Save button should now be working like Update button.
How can I do it?
Alternatively How can I make row editable?
Ideally you would wanna create the models as
Employee.Name , Employee.Age , Employee.City
Now
<table>
<tr>
<td style="text-align: right;">Name :
</td>
<td>
<input type="text" id="txtEmpName" ng-model="Employee.Name" />
</td>
</tr>
<tr>
<td style="text-align: right;">Age :
</td>
<td>
<input type="text" id="txtEmpAge" ng-model="Employee.Age" />
</td>
</tr>
<tr>
<td style="text-align: right;">City :
</td>
<td>
<input type="text" id="txtEmpCity" ng-model="Employee.City" />
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<button type="button" id="btnSubmit" ng-click="saveEmployee()">{{Employee.id ? "Edit" : "Create"}}</button>
</td>
</tr>
</table>
In the Controller
$scope.saveEmployee = function(){
if($scope.Employee.id){
// Id will be present for a existing employee
// update the Employee
}else {
// Id not present
// create the employee
}
}
I would have an Employee.save() in the model which can identify weather to save or update the Employee

Bootstrap dropdown using accordion is not working

I am implementing bootstrap dropdown in my Angular application using accordion. When I click on accordion toggle, it is not sliding down and up.
This is my code:
<div class="container-fluid mt100 mr5 ml5">
<div class="row">
<table class='table s12'>
<tr style="background: #e4e9eb;">
<td>Name</td>
<td>Address</td>
<td>City</td>
<td>Edit</td>
<td></td>
</tr>
<tr ng-repeat="listItem in Items">
<td>
{{listItem.name}}
</td>
<td>
{{listItem.address}}
</td>
<td>
{{listItem.city}}
</td>
<td>
<a class="dropdown-toggle" ng-click="isCollapsed = !isCollapsed" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
</a>
</td>
</tr>
<tr>
<td colspan="3" class="hiddenRow">
<div class="collapse" collapse="isCollapsed">
<table class="table display" style="border-collapse:collapse;">
<thead>
<tr class='pix2' style="background: #e4e9eb;">
<th>First</th>
<th>Second</th>
<th>Third</th>
</tr>
</thead>
<tbody>
<tr ng-repeat='item in listItem.subItems'>
<td>{{item.first}}</td>
<td>{{item.second}}</td>
<td>{{item.third}}</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</table>
</div>
</div>
What is causing the issue?

Resources