0

I'm scraping a page with some divs with the id = Content_Main_ some random number but can't get their content using the following xpath because the result is always empty, what I'm doing wrong?

//div[re:test(@id, '([Content_Main_]+\d{5}[0-9])')]

/div[@id='Content_Main_4']
/div[@id='Content_Main_5']
/div[@id='Content_Main_8']
Hana Iku
  • 11
  • 3

2 Answers2

0

I think you need something like (starting with Content_Main_ and next a digit):

//div[re:test(@id, 'Content_Main_\d+')]

UPDATE To select divs ending with a number you need:

//div[re:test(@id, 'Content_Main_\d+$')]
gangabass
  • 10,607
  • 2
  • 23
  • 35
  • I think I'm almost there, now the response is not empty but some divs I don't need are coming too, how can I change the expression to ignore divs like I'd = Content_Main_31_userControl_lbl_title and get only the ones who start with Content_Main_ and ends right after the number (Content_Main_4, Content_Main_5, etc)? – Hana Iku Jun 26 '19 at 10:10
0

You are searching exactly five digits after

text(Content_Main_)
\d{5}
  • Search 5 digits example : 12345; 76543....

make it like:

\d -- if it is always one digit
or
\d+ - if it can have one or more digit
or
\d* - if it may/may not have digit
Samsul Islam
  • 2,581
  • 2
  • 17
  • 23