xpath元素定位
1. / 和 //
/是直系查找;//是所有后代中查找
/html/body/div # 选择html下面的body下面的div元素
//div//p # 选择 所有的 div 元素里面的 所有的 p 元素
2. 根据属性定位
[@属性名=‘属性值’], eg: //*[@id=‘west’]
//*[@id='west'] # 选择 id 为 west 的元素
//select[@class='single_choice'] # 选择所有 select 元素中 class为 single_choice 的元素
3. 属性值包含字符串
//*[contains(@style,'color')] # 选择 style属性值 包含 color 字符串的 页面元素
//*[starts-with(@style,'color')] # 选择 style属性值 以 color 字符串 开头 的 页面元素
//*[ends-with(@style,'color')] # 选择 style属性值 以 某个 字符串 结尾 的 页面元素
//*[contains(text(), 'color')] # 选中文本中包含color的页面元素
4.按照次序选择
//p[2] # 选择 p类型第2个的子元素
//div/p[2] # 选取父元素为div 中的 p类型 第2个 子元素
//div/*[2] # 选择父元素为div的第2个子