有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Selenium WebDriver Java单击表中没有id的按钮

我正在尝试click一个位于表中的button

我尝试过按linkTextxPath搜索,但没有成功

我尝试过的代码是:

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,我似乎找不到元素

{cdi}在这里获取代码{cd5^>

<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>

共 (0) 个答案