【问题标题】:How to find Xpath for this?如何为此找到 Xpath?
【发布时间】:2015-04-29 06:44:26
【问题描述】:
<table cellspacing="0" cellpadding="0" width="50" border="0" style="border-collapse:collapse;">
<tr class="TabUnselected" valign="top" id="MainTabControl2">
<td width="5"><img width="5" height="5" border="0" src="images\eyebrow-upper-left-corner.gif" style="border-width:0px;" /></td><td><table cellspacing="3" cellpadding="0" width="99%" border="0">
<tr>
<td class="TabCaption" align="left" valign="bottom" OnClick="selectTab(2, 11, 'MainTabControl', 'Panel', 'lblTitle', 'paneltitle', 'hfldSelectedTab');" OnMouseOver="highlightTab('MainTabControl2', 'TabUnselected', 'TabHighlighted');" OnMouseOut="resetTab('MainTabControl2', 'TabUnselected', 'TabHighlighted');" style="white-space:nowrap;">**More Details**</td></tr>
</table>

我想点击更多详细信息(它似乎是一个链接)。

我尝试过使用 linkText 但返回异常..

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with link text == More Details (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 421 milliseconds

无论如何..如何识别xpath?

//*[@OnClick='selectTab(2, 11, 'MainTabControl', 'Panel', 'lblTitle', 'paneltitle', 'hfldSelectedTab')']

通过给 xpath 尝试这种方式.. 没有运气.. org.openqa.selenium.InvalidSelectorException: The xpath expression '//*[@OnClick='selectTab(2, 11, 'MainTabControl', 'Panel', ' lblTitle', 'paneltitle', 'hfldSelectedTab')'] ' 无法评估或不会产生 WebElement(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:157 毫秒

【问题讨论】:

    标签: selenium-webdriver


    【解决方案1】:

    尝试使用以下 xpath:

    //tr[@id='MainTabControl2']//td[@class='TabCaption']

    或者 //td[@class='TabCaption']

    已编辑:

    如果存在相同的 id 和 class,您可以使用元素的 text() 进行选择,如下所示:

    //td[contains(text(),'**More Details**')]

    【讨论】:

    • 喜欢更多细节,它有 8 个选项,并且都有相同的 id 和 class 值。它会工作吗??
    • org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == //tr[@id='MainTabControl2']/td[@class='TabCaption'] (警告:服务器没有提供任何堆栈跟踪信息)命令持续时间或超时:380 毫秒
    • @ChanGan 请检查我编辑的答案。另外请检查您刚刚发布的xpath
    • //td[contains(text(),'More Details')] 正在工作
    猜你喜欢
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多