XPath Checker

上一篇 / 下一篇  2008-03-10 11:07:50 / 个人分类:自动化测试

XPath Checker

[Updated with source code for developers.]

XPath Checkeris a Firefox Extension I wrote for testing XPath expressions interactively. You might find it useful if you use xpaths or want to learn how.

If you haven't used xpaths before, they are sort of like regular expressions for web pages. XPaths make it easy to extract content from deeply nested markup in a web page or an XML document. I find them most useful for unit-testing code that generates XML or HTML. They're also used in XSLT and by Firefox extensions such as Greasemonkey.

Here are some examples that you could try out using XPath Checker:

Get the title of a page:

//title/text()

List all the images on a page:

//img

List the images that are inside a link:

//a//img

List the images that have alt tags:

//img[@alt]

List the images thatdon'thave alt tags:

//img[not(@alt)]

Show all the alt tags:

//img/@alt

Show the href for every link:

//a/@href

Get an element with a particular CSS id:

//*[@id='mainContent']

To install XPath Checker, you need at least version 1.0.3 of Firefox. Once you have Firefox running, you can download XPath Checker fromaddons.mozilla.organd it will automatically install. Then you need to restart Firefox.

To use XPath Checker, right-click (or control-click if you have a Mac) anywhere on any web page and choose "View XPath" in the context menu. An editor window will pop up. The editor will show an XPath pointing to whatever you clicked on appear at the top of the window and the results of executing that XPath underneath. You can edit the XPath and the results automatically update as you type.

For developers: I'm releasing XPath Checker under the GPL. Here's thesource code. If you get stuck, send me email and maybe I'll write some documentation.


TAG: 自动化测试

 

评分:0

我来说两句

我的栏目

日历

« 2024-04-24  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 8113
  • 日志数: 8
  • 建立时间: 2008-03-06
  • 更新时间: 2009-03-06

RSS订阅

Open Toolbar