4
<div id="content-body-14269002-17290547">
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
</div>

I Need To Select Everything in id = "content-body*"

content-body changes on every Page, May Be Need to Use Wildcards ?

宏杰李
  • 11,820
  • 2
  • 28
  • 35
gaurav kumar
  • 65
  • 1
  • 1
  • 4
  • Does this answer your question? [xpath search for divs where the id contains specific text](https://stackoverflow.com/questions/12176723/xpath-search-for-divs-where-the-id-contains-specific-text) – Asalan Feb 16 '23 at 22:52

2 Answers2

15

Probably xpath search for divs where the id contains specific text Duplicate

Anyways,

For IDs

//div[contains(@id,"content-body")]//p #to Select all Paragraphs 

//div[contains(@id,"content-body")]//p//text() # To Select all text in Paragraphs 

For Classes

//*[contains(@class,"content-body")//p
//div[contains(@class,"content-body")]//p//text()

For Class in Class

//*[contains(@class,"content-body") and contains(@class,"another-sub-content-body")]//p//text()

Hope it Helps !!!

Community
  • 1
  • 1
3
//div[contains(@id, "content-body")]

This means content-body in content-body-14269002-17290547

Normally, this will works.

Better:

//div[starts-with(@id, "content-body")]

This means the id attribute's value is started with content-body

宏杰李
  • 11,820
  • 2
  • 28
  • 35