table 的大小,size() returns 0
size of a table, size() returns 0
您好,我正在尝试以这种方式获取 table 的行数:
int rows = findElements(By.xpath("//div[@class='communications-table ohim-table dataTable']/tbody/tr")).size();
但它 returns 0 行。我的 table 中确实有行,知道吗?谢谢
HTML:
<div class="box-content detailsBoxBody">
<div id="trademarksCommunicationsTable">
<div id="DataTables_Table_5_wrapper" class="dataTables_wrapper" role="grid">
<div class="datatables-top full-width">
<div id="DataTables_Table_5_processing" class="dataTables_processing" style="visibility: hidden;">Processing...</div>
<table id="DataTables_Table_5" class="communications-table ohim-table dataTable" aria-describedby="DataTables_Table_5_info">
<thead>
<tbody role="alert" aria-live="polite" aria-relevant="all">
<tr class="odd">
<tr class="even">
<tr class="odd">
<tr class="even">
<tr class="odd">
<tr class="even">
<tr class="odd">
<tr class="even">
<tr class="odd">
<tr class="even">
</tbody>
</table>
.....
您的 XPath 不可能:
By.xpath("//div[@class='communications-table ohim-table dataTable']/tbody/tr")
永远会找到 table
!
尝试:
By.xpath("//table[@id='DataTables_Table_5']//tr")
我认为等待也是一个问题。尝试使用 explicit
等待。而且,请注意我正在使用 css
By byCss = By.cssSelector(".communications-table.ohim-table.dataTable tr");
List<WebElements> elements = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfAllElementsLocatedBy(byCss));
elements.size();
您好,我正在尝试以这种方式获取 table 的行数:
int rows = findElements(By.xpath("//div[@class='communications-table ohim-table dataTable']/tbody/tr")).size();
但它 returns 0 行。我的 table 中确实有行,知道吗?谢谢
HTML:
<div class="box-content detailsBoxBody">
<div id="trademarksCommunicationsTable">
<div id="DataTables_Table_5_wrapper" class="dataTables_wrapper" role="grid">
<div class="datatables-top full-width">
<div id="DataTables_Table_5_processing" class="dataTables_processing" style="visibility: hidden;">Processing...</div>
<table id="DataTables_Table_5" class="communications-table ohim-table dataTable" aria-describedby="DataTables_Table_5_info">
<thead>
<tbody role="alert" aria-live="polite" aria-relevant="all">
<tr class="odd">
<tr class="even">
<tr class="odd">
<tr class="even">
<tr class="odd">
<tr class="even">
<tr class="odd">
<tr class="even">
<tr class="odd">
<tr class="even">
</tbody>
</table>
.....
您的 XPath 不可能:
By.xpath("//div[@class='communications-table ohim-table dataTable']/tbody/tr")
永远会找到 table
!
尝试:
By.xpath("//table[@id='DataTables_Table_5']//tr")
我认为等待也是一个问题。尝试使用 explicit
等待。而且,请注意我正在使用 css
By byCss = By.cssSelector(".communications-table.ohim-table.dataTable tr");
List<WebElements> elements = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfAllElementsLocatedBy(byCss));
elements.size();