【发布时间】:2014-11-14 13:26:52
【问题描述】:
我正在重构一个 RSS,所以我决定用 CasperJS 编写一些测试。
RSS 的元素之一是 "atom:link" (")
我尝试了这三个代码,但没有一个有效
test.assertExists("//atom:link", "atom:link tag exists.");
test.assertExists({
type: 'xpath',
path: "//atom:link"
}, "atom:link element exists.");
//even this...
test.assertExists({
type: 'xpath',
namespace: "xmlns:atom",
path: "//atom:link"
}, "atom:link element exists.");
RSS 代码是:
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xml:base="http://example.org/" xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/"
xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>RSS Title</title>
<description>RSS description</description>
<link>http://example.org</link>
<lastBuildDate>Mon, 10 Nov 2014 11:37:02 +0000</lastBuildDate>
<language>es-ES</language>
<atom:link rel="self" href="http://example.org/rss/feed.xml"/>
<item></item>
<item></item>
</channel>
</rss>
我在此页面http://www.freeformatter.com/xpath-tester.html 的演示中看到,foo:singers 可以通过以下方式访问:
//foo:singers
但在 CasperJS 中似乎这不起作用...
有人知道如何使用命名空间选择这种元素吗?
【问题讨论】:
标签: javascript xml xpath rss casperjs