XPath partial of attribute known

我是研究僧i 提交于 2019-11-30 04:52:13
Ronald Wildenberg

Your XPath expression should look like this:

//td[contains(@label, 'Choice 1')]/input

You select all td elements that have a label that contains Choice 1 and then you select the input elements inside these td elements.

EDIT: Tomalak's comment correctly suggests an improvement to prevent a match against 'Choice 11' (or 'Choice 12345', ...).

Found Ronald's solution while trying to find a way to test whether a node has either an attribute 'align' that is not empty OR an attribute 'style' that contains text value 'text-align'. These are the 'nodes' in question:

<node> 
  <p>This is left-aligned.</p> 
  <div align="left" >This is aligned LEFT using HTML attribute.</div> 
  <p style="text-align: center;" >This is centered using CSS style attribute.</p> 
  <div align="center" >This is CENTERED.</div> 
  <p style="text-align: right;" >This is right-aligned.</p> 
</this>

This xpath expression worked -- thanks to Ronald's answer that pointed me in the right direction:

//*[contains(@style, 'align') or @align!='']
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!