尝试使用contains来搜索一串文本

时间:2014-01-17 13:03:32

标签: html xpath

我正试图在页面上检查一些文字(“dateFormat”)......

这是我的HTML:

<div id="RsWidget" style="margin-top: 5px; margin:auto auto;">

<script src="dateFormat=dd-MM-yyyy" type="text/javascript"/>

我可以通过以下方式获得突出显示的文本行(脚本src):

.//*[@id='rswidget']/script[1]

现在,我只需要能够检查它是否包含“dateFormat”文本。

我已尝试.//*[@id='rswidget']/script[1]contains(., 'dateFormat')

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您不能在查询后使用and,或者您和the value returned by the query, which does not make any sense for a matched node. You need to put it in the [] condition. Also。`返回文本内容,而不是src属性(尽管属性中有格式)也没有多大意义。)

因此使用:

.//*[@id='rswidget']/script[1][contains(@src, 'dateFormat')]
相关问题