【每日一题0611】xpath 请选择不具有任何属性的div元素

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <AAA>
         <div id = "b1"></div>
         <div id = "b2"></div>
         <div name ="t1"></div>
         <div></div>
    </AAA>
</body>
</html>

结果:定位到<div></div>这个元素即可

附录:xpath 学习地址:https://www.w3school.com.cn/xpath/index.asp

/html/body/aaa/div[4]

/html/body/AAA/div[4]

document.getElementById(“div”)[4]

  • css selector: aaa > div:not([id])+div

  • xpath: //div[not(@id) and not(@name)]

//div[4]