LoginSignup
1
0

ブラウザで XPATH 式を確認するためのTIPS

Last updated at Posted at 2023-06-20

目的

Seleniumなどで使えるXPATH式を作成したい

方法

F12 (開発者ツール) のJavascript Consoleにて以下の関数を流し込みます。

function printXpathAll(xpath) {
    var xpath_result = document.evaluate(xpath, document, null, XPathResult.ANY_TYPE, null); 
    var next = xpath_result.iterateNext(); 
    while (next) {
        console.log(next);
        next = xpath_result.iterateNext();
    }
}

image.png

使用例

"//a" だと、候補が多数表示されます:
image.png

"//a[text() = '開発者']" にて候補を絞り込めました:
image.png

1
0
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
1
0