我正在尝试click
位于表格中的button
。
我已尝试按linkText
和xPath
搜索但未成功。
我尝试过的代码是:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.switchTo().frame(driver.findElement(By.xpath("//div[@class='ddial_o']")));
WebElement table = driver.findElement(By.xpath("//table[@class='ddial_b']"));
table.findElement(By.xpath("//tbody/tr/td/a[contains(text(), 'OK')]")).click();
我使用list来确保实际找到该元素,虽然list.size()显示为我的命令的2和1,但我似乎无法找到该元素。
以下是页面的HTML
代码,我不断获得NoSuchElementException
<div style="z-index: 1004; width: 400px; left: 596px; top: 70px;" class="ddial_o">
<div class="ddial_o2">
<div class="ddial_i"><a style="outline: medium none;" class="d2l-offscreen" href="javascript://">Jump to bottom of Confirmation dialog</a>
<div class="ddial_t d2l-dragdrop-draggable">
<table width="100%">
<tbody>
<tr>
<td></td>
<td class="ddial_h"><a style="outline: medium none;" tabindex="-1"><h1>Confirmation</h1></a>
</td>
<td class="ddial_close"><a title="Close this Dialog" style="display: none;" href="javascript://"><span><span class="d2l-offscreen">Close this Dialog</span></span></a>
</td>
</tr>
</tbody>
</table>
</div>
<table width="100%">
<tbody>
<tr>
<td style="width: 1%;" valign="top"><img style="width: 48px; height: 48px; padding: 7px 0px 7px 7px;" src="/d2l/img/lp/dialog/confirm.gif">
</td>
<td valign="top">
<div style="overflow: auto; margin: 10px;" class="ddial_c">
<div>
<p style="margin-top: 0px; font-weight: bold; display: block;">The quiz you are about to begin may take a few minutes to load.
<br>
<br>
</p>
<p style="margin-bottom: 0px; display: block;">The timer will not begin until after the set up process is finished.
<br>
<br>You can submit your quiz responses past the time period allocated for taking this quiz, but doing so will result in a score of zero being assigned.Click OK to start your quiz or click Cancel if you do not wish to start it now.</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<table style="display: block;" class="ddial_b">
<tbody>
<tr>
<td><a aria-disabled="false" tabindex="0" role="button" class="vui-button d2l-button vui-button-primary">OK</a><a aria-disabled="false" tabindex="0" role="button" class="vui-button d2l-button">Cancel</a>
</td>
<td align="center" width="100%"></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<a style="outline: medium none;" title=" " tabindex="-1"> </a><a style="outline: medium none;" class="d2l-offscreen" href="javascript://">Jump to top of Confirmation dialog</a>
</div>
<div class="ddial_f"><span aria-live="assertive"></span>
<div title="Resize this Dialog" class="ddial_fr"></div>
<div class="clear d2l-clear"></div>
</div>
</div>
</div>