0

我需要双击表格内的元素(命名用户)。尝试使用 xpath,但我收到一条错误消息,提示“无法找到元素”。我还尝试了 className、linkText、tagName。任何人都可以取悦这个。

这是一段html代码

<div id="gridpanel-1064" class="x-panel filesystem-filegrid x-grid-with-row-lines x-border-item x-box-item x-panel-default x-grid" style="right: auto; left: 305px; top: 0px; margin: 0px; width: 1373px; height: 343px;">
<div id="gridpanel-1064_header" class="x-panel-header x-docked x-panel-header-default x-docked-top x-panel-header-docked-top x-panel-header-default-docked-top x-layout-fit" style="width: 1373px; right: auto; left: 0px; top: 0px;">
<div id="toolbar-1075" class="x-toolbar x-docked x-toolbar-default x-docked-top x-toolbar-docked-top x-toolbar-default-docked-top x-box-layout-ct" style="width: 1373px; right: auto; left: 0px; top: 32px;">
<div id="headercontainer-1065" class="x-grid-header-ct x-docked x-grid-header-ct-default x-docked-top x-grid-header-ct-docked-top x-grid-header-ct-default-docked-top x-box-layout-ct" style="border-width: 1px; width: 1373px; right: auto; left: 0px; top: 59px;">
<div id="gridpanel-1064-body" class="x-panel-body x-grid-body x-panel-body-default x-layout-fit x-panel-body-default" style="width: 1373px; left: 0px; height: 226px; top: 84px;">
    <div id="gridview-1074" class="x-grid-view x-fit-item x-grid-view-default x-unselectable" style="overflow: auto; margin: 0px; width: 1371px; height: 224px;" tabindex="-1">
        <table id="gridview-1074-table" class="x-gridview-1074-table x-grid-table" cellspacing="0" cellpadding="0" border="0" tabindex="-1" style="width: 918px;">
            <colgroup>
            <colgroup>
            <colgroup>
            <colgroup>
            <colgroup>
            <colgroup>
            <colgroup>
            <colgroup>
            <colgroup>
            <tbody id="gridview-1074-body">
                <tr id="gridview-1074-record-ext-record-23" class="x-grid-row x-grid-data-row" tabindex="-1" data-recordindex="0" data-recordid="ext-record-23" data-boundview="gridview-1074">
                <tr id="gridview-1074-record-ext-record-24" class="x-grid-row x-grid-row-alt x-grid-data-row" tabindex="-1" data-recordindex="1" data-recordid="ext-record-24" data-boundview="gridview-1074">
                <tr id="gridview-1074-record-ext-record-25" class="x-grid-row x-grid-data-row" tabindex="-1" data-recordindex="2" data-recordid="ext-record-25" data-boundview="gridview-1074">
                <tr id="gridview-1074-record-ext-record-26" class="x-grid-row x-grid-row-alt x-grid-data-row" tabindex="-1" data-recordindex="3" data-recordid="ext-record-26" data-boundview="gridview-1074">
                <tr id="gridview-1074-record-ext-record-27" class="x-grid-row x-grid-data-row" tabindex="-1" data-recordindex="4" data-recordid="ext-record-27" data-boundview="gridview-1074">
                    <td class="x-grid-cell x-grid-td x-grid-cell-gridcolumn-1100 x-grid-cell-first x-unselectable x-grid-cell-special x-grid-cell-row-checker">
                    <td class="x-grid-cell x-grid-td x-grid-cell-actioncolumn-1066 x-unselectable x-action-col-cell">
                    <td class="x-grid-cell x-grid-td x-grid-cell-gridcolumn-1067 x-unselectable ">
                        <div class="x-grid-cell-inner" style="text-align:left;" unselectable="on">users</div>
                    </td>
                    <td class="x-grid-cell x-grid-td x-grid-cell-actioncolumn-1068 x-unselectable x-action-col-cell">
                    <td class="x-grid-cell x-grid-td x-grid-cell-gridcolumn-1069 x-unselectable ">
                    <td class="x-grid-cell x-grid-td x-grid-cell-gridcolumn-1070 x-unselectable ">
                    <td class="x-grid-cell x-grid-td x-grid-cell-gridcolumn-1071 x-unselectable ">
                    <td class="x-grid-cell x-grid-td x-grid-cell-gridcolumn-1072 x-unselectable ">
                    <td class="x-grid-cell x-grid-td x-grid-cell-gridcolumn-1073 x-grid-cell-last x-unselectable ">
                </tr>
            </tbody>
        </table>
    </div>
</div>
4

4 回答 4

0

那么您当前的 XPath 是错误的:

//table/tbody/tr[5]/tr[3]/div

看看它做了什么。

它会进入table,进入 that tabletbody进入第五 tr(行),然后错误是,它会进入第三 tr(行,记得吗?)

拿它和你所拥有的进行比较。

您可能想要:

//table/tbody/tr[5]/td[3]/div

如中,第五个tr(行)内的第三个 td(单元格)。

于 2013-06-12T20:38:12.187 回答
0

此 XPath 将选择包含users其类为的文本的 divx-grid-cell-inner


XPath

//div[contains(., 'users') and contains(@class, 'x-grid-cell-inner')]

查找元素

<div class="x-grid-cell-inner" style="text-align:left;" unselectable="on">users</div>

如果有多个具有这些属性的 div,则需要对 XPath 应用额外的限定符。

于 2013-06-12T21:02:59.130 回答
0

希望对你有帮助...

driver.findElement(By.xpath("//table[@id='gridview-1074-table']/tbody/tr[5]/tr[3]/div")).click();
于 2013-06-13T13:00:42.807 回答
0

也许是这样的:

driver.findElement(By.xpath("//div[contains(string(), 'users')]"));
于 2013-06-13T13:55:42.107 回答