如何在 xpath 中找到子字符串

Nye*_*ard -2 html xpath

我需要在 selenium 2 中找到一个元素,并且我知道我正在查找的链接包含我在变量中获得的一些已定义文本。所以链接是这样的:

<a id="ctl00_content_list_gvOtherSchemas_ctl02_lbViewSchema"
  href="javascript:WebForm_DoPostBackWithOptions(new
   WebForm_PostBackOptions(&quot;ctl00$content$list$gvOtherSchemas$ctl02
     $lbViewSchema&quot;, &quot;&quot;, false, &quot;&quot;,
     &quot;https://test/page.aspx?_InfoPath_Sentinel=1&amp;
   case=2011-015196&amp;name=MyCase&amp;version=2&amp;p=PPC1&amp;cc=ANSOEG&amp;
   py=2011&amp;rn=CR274&amp;c=0&amp;st=DRAFT&amp;oo=1&amp;sc=SC001&amp;hln=&amp;
   tl=31-12-2011 23:59:59&amp;sa=&amp;sai=&amp;san=&quot;, false, true))"
>MyCase</a>
Run Code Online (Sandbox Code Playgroud)

我想通过 xpath 表达式查找文本:“case=2011-015196”。

Lar*_*rsH 5

我想找到包含某些给定文本的元素,在我的例子中是文本 2011-015196

使用此 XPath:

//*[@*[contains(., '2011-015196')]]
Run Code Online (Sandbox Code Playgroud)

我如何使用 Xpath 找到回发中的文本?

用这个:

string-length(substring-before(//*/@*[contains(., '2011-015196')],
                               '2011-015196'))
Run Code Online (Sandbox Code Playgroud)

2011-015196这将告诉您包含它的属性内的偏移量。