简体   繁体   中英

Xpath select element where both children contains text

How do I select an element where both of the children contains a specific text.

Example:

<div class="line">
     <h1>
          <a>1</a>
     </h1>
     <p>
          <a>2</a>
     </p>
</div>
<div class="line">
     <h1>
          <a>3</a>
     </h1>
     <p>
          <a>4</a>
     </p>
</div>

How do I make an XPath string that, search for the class line, and then select it where one of the spans contain 3 and 4

I tried this

//div[contains(@class, 'line')]

but I don't see how I can select it where first child contains 3 and second contains 4 .

尝试通过两个子节点的确切字符串值选择div节点

//div[contains(@class, 'line') and normalize-space(h1)='3' and normalize-space(p)='4']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM