I am testing a web application with web driver I have this dynamic table generated when I enter a keyword and click search button:
<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>
What I want to do is loop through the table and extract the value between tags.
In the code above the value I would like to extract is : TSK(BEN721JUU5)(000)
I have written the following code so far, but I don't know why this is not printing anything.
@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());
}
}
}