0
我測試用捲筒紙驅動器 Web應用程序我有,當我輸入一個關鍵字,然後點擊搜索按鈕生成此動態表:無法從一個HTML動態表中獲取數據
<div id="mainView">
<div class="table-responsive">
<table id="search_results_table" class="table table-striped table-hover table-condensed table-bordered">
<tbody>
<tr class="ng-scope" ng-repeat="object in objects">
<td>
<a href="#/en/object?company=WAR001&area=X&mu=BIST_CE466&name=TSK(BEN721JUU5)(000)">
<b class="ng-binding">TSK(BEN721JUU5)(000)</b>
</a>
<p style="font-size:11px">
</td>
</tr>
</tbody>
</table>
我想什麼do循環遍歷表並提取標籤之間的值。 在上面的代碼中,我想提取的值是:TSK(BEN721JUU5)(000)
到目前爲止我寫了下面的代碼,但我不知道爲什麼這不是打印任何內容。
@Test
private void srch() throws MalformedURLException, IOException {
driver.get(TestURL);
WebElement input1 = driver.findElement(By.id("login_form_user_input"));
input1.sendKeys("guest");
WebElement input2 = driver.findElement(By.id("login_form_password_input"));
input2.sendKeys("guest");
WebElement btn = driver.findElement(By.id("login_form_signin_button"));
btn.click();
WebElement w1 = driver.findElement(By.id("header_search_text_field"));
w1.sendKeys("tsk");
WebElement resulttable = driver.findElement(By.id("search_results_table"));
List<WebElement> rows = resulttable.findElements(By.tagName("tr"));
for (WebElement row : rows) {
List<WebElement> cols = row.findElements(By.tagName("td"));
System.out.println(cols.size());
for (int i = 0; i < cols.size(); i++) {
WebElement data = cols.get(i);
System.out.println(data.getText());
}
}
}