私はXpathで練習していましたが、要素を取得できません。私のコードは簡単です:
<html>
<script>
//get first div
var headings = document.evaluate('//h2', document, null, XPathResult.ANY_TYPE, null );
var res = headings.iterateNext()
while(res){
console.log(res);
var res = headings.iterateNext()
}
console.log(headings);
</script>
<body>
<div>HI!!!</div>
<h2> JOE </h2>
</body>
</html>
これは undefined を返します。可能なすべての xpathExpression を試しました (firefox と chrome でテスト済み)。何か助けはありますか?
ありがとう!