我想獲得表格中的行數。 我已經在幾個方面嘗試過(沒有成功),最後我已經嘗試過通過以下方式:獲取表格中的行數
var _tableOfInterestsCount = wait.Until(x => x.FindElements(By.XPath("//*[@id='gridBodyTable']/tbody")));
var _trs = wait.Until(x => x.FindElements(By.XPath(".//tr[@class = 'ms-crm-List-Row']")));
在調試時,我得到計數= 1,同時有3行。當然。 所有3 tr都有相同的類。 此外,甚至還有在這個表中的屬性說:numrecords="3"
並用下面的時候,再一次,我越來越而不是3
var _tableOfInterestsCount = wait.Until(x => x.FindElement(By.XPath("//*[@id='gridBodyTable']")).GetAttribute("numrecords"));
相關的HTML代碼的值爲1:
<table class="ms-crm-List-Data" cellspacing="0" cellpadding="1" rules="rows" morerecords="0" totalrecordcount="3" allrecordscounted="1" oname="10046" numrecords="3" tabindex="0" primaryfieldname="new_name" summary="foo" border="1" id="gridBodyTable" style="border-style:None;border-collapse:collapse;">
\t \t <colgroup><col width="18px" class="ms-crm-List-CheckBoxColumn"><col width="302" name="new_name" class="ms-crm-List-DataColumn ms-crm-List-SortedColumn"><col width="127" name="createdon" class="ms-crm-List-DataColumn"><col></colgroup><thead><tr class="ms-crm-Hidden-List"><th scope="col" class="ms-crm-Hidden-List"></th><th scope="col" class="ms-crm-Hidden-List">שם</th><th scope="col" class="ms-crm-Hidden-List">created at</th></tr></thead><tbody><tr class="ms-crm-List-Row" oid="{5843AB8E-39F7-E611-BE37-00155D47B163}" otype="10046" otypename="new_contact_content" selected="false">
\t \t \t <td class="ms-crm-List-NonDataCell" align="center"><input type="checkbox" class="ms-crm-RowCheckBox" id="checkBox_{5843AB8E-39F7-E611-BE37-00155D47B163}" tabindex="0" title="1" style=" "></td><td class="ms-crm-List-DataCell inner-grid-cellPadding"><nobr class="gridcellpadding" title="name1"><a href="#" id="gridBodyTable_primaryField_{5843AB8E-39F7-E611-BE37-00155D47B163}_0" target="_self" title="name 1" class="ms-crm-List-Link" tabindex="0">name 1</a></nobr></td><td class="ms-crm-List-DataCell inner-grid-cellPadding ms-crm-NumbersAndDates"><nobr class="gridcellpadding" title="20/02/2017 08:55">20/02/2017 08:55</nobr></td><td class="ms-crm-List-DataCell"><nobr class="gridcellpadding"></nobr></td>
\t \t </tr><tr class="ms-crm-List-Row" oid="{5943AB8E-39F7-E611-BE37-00155D47B163}" otype="10046" otypename="new_contact_content" selected="false">
\t \t \t <td class="ms-crm-List-NonDataCell" align="center"><input type="checkbox" class="ms-crm-RowCheckBox" id="checkBox_{5943AB8E-39F7-E611-BE37-00155D47B163}" tabindex="0" title="3" style=" "></td><td class="ms-crm-List-DataCell inner-grid-cellPadding"><nobr class="gridcellpadding" title="3"><a href="#" id="gridBodyTable_primaryField_{5943AB8E-39F7-E611-BE37-00155D47B163}_1" target="_self" title="3" class="ms-crm-List-Link" tabindex="0">3</a></nobr></td><td class="ms-crm-List-DataCell inner-grid-cellPadding ms-crm-NumbersAndDates"><nobr class="gridcellpadding" title="20/02/2017 08:55">20/02/2017 08:55</nobr></td><td class="ms-crm-List-DataCell"><nobr class="gridcellpadding"></nobr></td>
\t \t </tr><tr class="ms-crm-List-Row" oid="{5A43AB8E-39F7-E611-BE37-00155D47B163}" otype="10046" otypename="new_contact_content" selected="false">
\t \t \t <td class="ms-crm-List-NonDataCell" align="center"><input type="checkbox" class="ms-crm-RowCheckBox" id="checkBox_{5A43AB8E-39F7-E611-BE37-00155D47B163}" tabindex="0" title="9" style=" "></td><td class="ms-crm-List-DataCell inner-grid-cellPadding"><nobr class="gridcellpadding" title="9"><a href="#" id="gridBodyTable_primaryField_{5A43AB8E-39F7-E611-BE37-00155D47B163}_2" target="_self" title="9" class="ms-crm-List-Link" tabindex="0">9</a></nobr></td><td class="ms-crm-List-DataCell inner-grid-cellPadding ms-crm-NumbersAndDates"><nobr class="gridcellpadding">20/02/2017 08:55</nobr></td><td class="ms-crm-List-DataCell"><nobr class="gridcellpadding"></nobr></td>
\t \t </tr></tbody>
\t </table>
編輯: 順便說一句,當有2行,計數爲0。 我甚至嘗試以下,但仍然得到錯誤的adttribute的值:
Dictionary<string, object> attributes = executor.ExecuteScript("var items = {}; for (index = 0; index < arguments[0].attributes.length; ++index) { items[arguments[0].attributes[index].name] = arguments[0].attributes[index].value }; return items;", _tableOfInterestsCount) as Dictionary<string, object>;
你能分享相關的HTML嗎? –
numrecords =「3」與GetAttribute(「numberrecords」),應該是不同的? – drw85
@ drw85對不起,修復它。它應該是numrecords,但它不是問題:) –