gpt4 book ai didi

java - 表中相关元素的 XPath

转载 作者:行者123 更新时间:2023-12-03 15:59:04 24 4
gpt4 key购买 nike

我正在使用 Java Selenium 根据输入的标题打开链接。我有以下 HTML 部分,其中 Top 5 Item Exception Types是我需要找到的标题及其超链接 <a class="CatalogActionLink" href="javascript:void(null)">Open</a>在另一个<tr><td><span>其兄弟旁边的标签 <tr><td><span>标签。我怎样才能找到元素 Open通过搜索标题超链接 Top 5 Item Exception Types

<table cellspacing="4" cellpadding="0" border="0">
<tbody>
<tr>
<td class="CatalogObjectListItemIcon" rowspan="2"><img src="/analytics/res/sk_blafp/catalog/obj_request_b.png" alt="Analysis" title="Analysis"></td>
<td><span class="CatalogObjectListItemTitle">Top 5 Item Exception Types</span>
<span class="CatalogObjectListItemLastModifiedTime">Last Modified 2/15/2018 12:39:45 PM</span>
<span class="CatalogObjectListItemOwner">Owner System Account</span>
</td>
</tr>
<tr>
<td>
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><a class="CatalogActionLink" href="javascript:void(null)">Open</a></td>
<td><span class="CatalogActionLinkSeparator">&nbsp;</span>
</td>
<td><a class="CatalogActionLink" href="javascript:void(null)">Edit</a></td>
<td><span class="CatalogActionLinkSeparator">&nbsp;</span>
</td>
<td><a class="CatalogActionLink" href="javascript:void(null)" title="Click to see more actions of Top 5 Item Exception Types">More<img border="0" src="/analytics/res/s_FusionFX/uicomponents/obips.UberBar/dropdown_n.png" alt="Dropdown menu">
</a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>

我可以使用以下方法找到标题

WebElement reportElement = driver.findElement(
By.xpath("//span[contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),'"
+ reportName.toLowerCase() + "')]"));

最佳答案

试试这个:

//span[text()='Top 5 Item Exception Types']/ancestor::tr/following-sibling::tr/descendant::a[text()='Open']

关于java - 表中相关元素的 XPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50148810/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com