21.xpath定位中id 、starts-with、contains、text()和last() 的用法

xpath语法:id 、starts-with、contains、text()和last() 的用法

   <input id="su" class="bg s_btn btnhover" value="百度一下" type="submit"/>
   //*[@id='su'] 获取id 的属性为'su' 的值
   或
   //input[contains(@class,'bg s_btn')]

 <a class="lb" href="https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F" name="tj_login" onclick="return false;">登录</a>
 //a[starts-with(@name,'tj_lo')]     属性模糊定位
//a[contains(@name,'tj_lo')] 属性模糊定位

  <a href="http://www.baidu.com">百度搜索</a>
  //a[text()='百度搜索']
  或
  //a[contains(text(),"搜索")] --文本模糊定位

  <a id="setf" href="//www.baidu.com/cache/sethelp/help.html" onmousedown="return ns_c({'fm':'behs','tab':'favorites','pos':0})" target="_blank">把百度设为主页</a>
  //a[text()='把百度设为主页']



原文地址:https://www.cnblogs.com/lvjing/p/9857473.html