XPath - 验证@title 的内容

XPath - verify contents of @title

我的问题的背景信息:
我在 FitNesse 工作,通常我可以使用 CSS 选择器来查找和验证我想要的元素。但是,在这种情况下,我需要通过 XPath 检查 @title 属性,但我在这样做时遇到了麻烦。

我的 FitNesse 场景是这样的:

| ensure | do | verifyText | on | !-xpath statement to the @title attribute here-! | with | @the_title_I_expect

这意味着我需要找到@title 元素的 XPath 来验证它,而不是在我的 XPath 表达式中包含带有内容的@title。

有人可以帮我吗?

示例:

<th id="scollTable.titleRow.column2" title="**This is my title**" colspan="1" scope="col" class="detailTableHeader">Some text here I don't care about</th>

我想检查文本 'This is my title' 的有效性。 任何指针?提前致谢!

您正在使用 Xebium?我相信他们有(实际上他们使用的 Selenium 1 API 有)一个命令 verifyAttribute 可以用来检查属性而不是元素的文本。 (很快google给了我this example page。)

所以我相信你的行会变成:

| ensure | do | verifyAttribute | on | xpath=//th[@id='scollTable.titleRow.column2']@title| with | !-**This is my title**-!|

P.S。我对 Xebium 不是很熟悉,但我相信你可以将这样的一行重写为 check 而不是 ensure 这样你的测试报告就会在测试失败时显示实际的标题,而不是刚刚报告 'failed'.