LoginSignup
22
28

More than 5 years have passed since last update.

よく使うXPath

Last updated at Posted at 2015-06-10

XPath便利ですよね。でもちょっと時間が経つとパスの指定の仕方をすっかり忘れてしまいます。
備忘録的によくつかうものをまとめておきます。

パス 意味
/ てっぺん。ルート
/html ルート直下のhtml要素。普通のHTMLなら普通の形
div 手当たり次第、全部のdiv
[@hoge=fuga] hoge属性がfugaである全ての要素
div[@hoge=fuga] hoge属性がfugaである全てのdiv
[@hoge='3'] hoge属性が3である全ての要素
/html/body/div/div/div てっぺんから深い階層のdivをたどる
div/div 全ての「divの中のdiv」。
だとidが2のdivにも3のdivにもマッチ。
div//div divの直接の子、または子孫であるdiv
div/* divの全ての直接の子
div/*[1] divの全ての直接の子の中で最初に見つかったもの
div/@id 全てのdivタグのid属性
div/*/@id divの直接の子の全ての要素のid属性
div//* divの直接の子、または子孫であるすべての要素
div//*[1] divの直接の子、または子孫の要素の中で、それぞれの直接の親から見て最初の要素
//div ルートの直接の子、または子孫である全てのdiv要素
22
28
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
28