The HTML I'm trying working with is below,
<div id="enquiry-header-grid-SalesTransactionEnquiry-enquiry-header-grid-wrapper" class="enquiry-kendo-grid-wrapper k-grid k-widget" data-role="grid" style="height: 456px;">
<div class="k-grid-content k-auto-scrollable" style="height: 428px;">
<table role="grid" tabindex="0" data-role="selectable" class="k-selectable" style="touch-action: none;">
<colgroup><col style="width:120px"><col style="width:120px"><col style="width:100px"><col style="width:60px"><col style="width:100px"><col style="width:105px"><col style="width:100px"><col style="width:120px"><col style="width:120px"><col style="width:100px"><col style="width:200px"><col style="width:120px"><col style="width:120px"><col style="width:60px"><col style="width:100px"><col style="width:100px"><col style="width:100px"><col style="width:100px"><col style="width:100px"><col style="width:120px"><col style="width:60px"><col style="width:100px"><col style="width:100px"></colgroup>
<tbody role="rowgroup">
<tr data-uid="23f8ebd0-2c90-4728-9430-71376f2d10e3" role="row" class="k-state-selected" aria-selected="true">
<td class="col-align-left" role="gridcell"><a href="#" class="cell-popover" data-col-type="popover" data-col-name="ST_COPYCUST">MUFC</a></td>
<td class="col-align-left" role="gridcell">Manchester United</td>
<td class="col-align-right" role="gridcell">23/10/2017</td>
<td class="col-align-right" role="gridcell">1</td>
<td class="col-align-left" role="gridcell">Invoice</td>
<td class="col-align-left" role="gridcell">1000</td>
<td class="col-align-center" role="gridcell"><input type="checkbox" disabled="disabled"></td>
<td class="col-align-right" role="gridcell">5.00</td>
<td class="col-align-right" role="gridcell">1.00</td>
<td class="col-align-left" role="gridcell">SA</td>
<td class="col-align-left" role="gridcell"></td>
<td class="col-align-right" role="gridcell">6.00</td>
<td class="col-align-left" role="gridcell">0.00</td>
<td class="col-align-center" role="gridcell"><input type="checkbox" disabled="disabled"></td>
<td class="col-align-left" role="gridcell">2017</td>
<td class="col-align-left" role="gridcell">1</td>
<td class="col-align-right" role="gridcell">23/10/2017</td>
<td class="col-align-right" role="gridcell">23/10/2017</td>
<td class="col-align-left" role="gridcell"></td>
<td class="col-align-left" role="gridcell">0.00</td>
<td class="col-align-center" role="gridcell"><input type="checkbox" disabled="disabled"></td>
<td class="col-align-left" role="gridcell"></td><td class="col-align-left" role="gridcell"></td></tr>
<tr class="k-alt" data-uid="5a1d2279-5588-4c41-ab22-ce5361192a4c" role="row">
Clicking the below opens a modal window but I'm struggling to get the click to work,
<td class="col-align-left" role="gridcell"><a href="#" class="cell-popover" data-col-type="popover" data-col-name="ST_COPYCUST">MUFC</a></td>
As the table is dynamic I don't think I can use the XPath, the code at present looks like this,
driver.FindElement(By.ClassName("cell-popover")).Click();
Which works great as long as the cell is on the first row of the table, however this will not always be the case so would like some advice\help on how to proceed?
UPDATE
Solved it with this,
IWebElement elemTable = driver.FindElement(By.Id("enquiry-header-grid-SalesTransactionEnquiry-enquiry-header-grid-wrapper")).FindElement(By.TagName("tbody"));
List<IWebElement> lstTrElem = new List<IWebElement>(elemTable.FindElements(By.TagName("tr")));
IWebElement row = lstTrElem.Where(item => item.Text.Contains("LU1")).FirstOrDefault();
string rowid = row.GetAttribute("data-uid");
IList<IWebElement> cells = row.FindElements(By.TagName("td"));
for (int i = 0; i < cells.Count; i++)
{
IWebElement cell = cells[i];
}
row.FindElement(By.ClassName("cell-popover")).Click();
As the td containing "LU1" is always unique, be intersted to know if there is a more efficient\reliable way of doing it though!
Second Update
Refined it slightly to the following,
IWebElement elemTable = driver.FindElement(By.Id("enquiry-header-grid-SalesTransactionEnquiry-enquiry-header-grid-wrapper")).FindElement(By.TagName("tbody"));
List<IWebElement> lstTrElem = new List<IWebElement>(elemTable.FindElements(By.TagName("tr")));
IWebElement row = lstTrElem.Where(item => item.Text.Contains("LU1")).FirstOrDefault();
string rowid = row.GetAttribute("data-uid");
row.FindElement(By.ClassName("cell-popover")).Click();
Seems to be reliable
By.LinkText("MUFC")
orBy.CssSelector("[data-col-name='ST_COPYCUST']")
orBy.XPath("//a[normalize-space()='MUFC']")
. You may need to use a waiter if the content is created dynamically.