我正在尝试在这里使用一张桌子,它把我的头煮得很脆。所以测试是,加载页面并确认“加载计划”按钮在那里。还断言表标题存在并包含预期的文本。这是完整且有效的。这是点击“加载计划”之前的 HTML</p>
<table id="scheduleTable" class="audit_table">
<thead>
<tr>
<th class="date-header red_grade">Kick Off(UTC)</th>
<th class="narrow-header red_grade">RBallId</th>
<th class="narrow-header red_grade">GSMId</th>
<th class="narrow-header red_grade">WBId</th>
<th class="country-header red_grade">Country</th>
<th class="header red_grade" style="display:none">Sport</th>
<th class="header red_grade" style="display:none">SportId</th>
<th class="header red_grade">League</th>
<th class="header red_grade ">Home</th>
<th class="header red_grade">Away</th>
<th class="header red_grade">Languages</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
现在,当我单击 Load Schedule 按钮时,页面中会添加一个新的“tbody”元素,如下所示:
<tbody><tr class="odd">
<td class="Kickoff">2013-09-02 14:30:00</td>
<td class="RBallId">327097</td>
<td class="GSMId">0</td>
<td class="WBId">0</td>
<td class="Country">South Africa-(82)</td>
<td class="Sport" style="display:none">Soccer</td>
<td class="SportId" style="display:none">1</td>
<td class="League">Varsity Football Challenge</td>
<td class="Home">University of the Western Cape - UWC (students)</td>
<td class="Away">University of Cape Town - UCT (students)</td>
<td class="Languages"></td>
</tr><tr class="even">
<td class="Kickoff">2013-09-02 14:45:00</td>
<td class="RBallId">338082</td>
<td class="GSMId">0</td>
<td class="WBId">0</td>
<td class="Country">Friendly-(20)</td>
<td class="Sport" style="display:none">Soccer</td>
<td class="SportId" style="display:none">1</td>
<td class="League">Friendly INT Women U19</td>
<td class="Home">Greece U19</td>
<td class="Away">Turkey U19</td>
<td class="Languages"></td>
</tr><tr class="odd">
<td class="Kickoff">2013-09-02 15:00:00</td>
<td class="RBallId">336937</td>
<td class="GSMId">1421234</td>
<td class="WBId">0</td>
<td class="Country">Estonia-(2)</td>
<td class="Sport" style="display:none">Soccer</td>
<td class="SportId" style="display:none">1</td>
<td class="League">Meistriliiga</td>
<td class="Home">Kalju</td>
<td class="Away">Kuressaare</td>
<td class="Languages"></td>
</tr><tr class="even">
<td class="Kickoff">2013-09-02 15:00:00</td>
<td class="RBallId">331340</td>
<td class="GSMId">1571623</td>
<td class="WBId">0</td>
<td class="Country">Sweden-(48)</td>
<td class="Sport" style="display:none">Soccer</td>
<td class="SportId" style="display:none">1</td>
<td class="League">U21 B-Playoffs</td>
<td class="Home">Halmstad U21</td>
<td class="Away">Kalmar U21</td>
<td class="Languages"></td>
</tr><tr class="odd">
<td class="Kickoff">2013-09-02 15:00:00</td>
<td class="RBallId">331348</td>
<td class="GSMId">1571636</td>
<td class="WBId">0</td>
<td class="Country">Sweden-(48)</td>
<td class="Sport" style="display:none">Soccer</td>
<td class="SportId" style="display:none">1</td>
<td class="League">U21 B-Playoffs</td>
<td class="Home">Åtvidaberg U21</td>
<td class="Away">Gefle U21</td>
<td class="Languages"></td>
</tr><tr class="even">
等等等等。
我想要做的是在单击按钮之前检查是否唯一可见的是标题,然后当我单击“加载计划”按钮时,我想获取行数并断言它> 0。
我已经尝试了这里和谷歌的几个例子,但并没有很高兴让它们以我希望的方式工作。
我做了下面的另一种方法,但失败了:
private boolean isElementPresent(WebDriverBackedSelenium webBrowser, String xpath) {
try {
driver.getWrappedDriver().findElement(By.xpath("//*[@id=\"scheduleTable\"]/tbody/tr[1]"));
return true;
} catch (Exception e) {
return false;
}
}
像往常一样,我很感激花时间帮助我解决这个问题