2013-11-21 67 views
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()); 
      } 
    } 
} 

回答