S
S
sivabur2015-05-25 13:40:02
C++ / C#
sivabur, 2015-05-25 13:40:02

How to get an element with a class by pattern/mask (xpath)?

Fits:

<div class="class1-s"> 
<div class="class1_a">

Not suitable: That is, the template (mask) class1** *-any character (optional/required 2 options are needed.)
<div class="class1-s1">

//*[contains(@class, 'class1')].  не подходит берет всё где находит class1qq.

I use htmlagilitypack c# I check
in chrome.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Fov, 2017-09-28
@Roman-Fov

<root>
  <div class="class1-s">a</div>
  <div class="class1_a">b</div>
  <div class="  class1+g 	">b</div>
  <div class="class1-s1">c</div>
  <div class="class1-s134">c</div>
  <div class="cls1-s134">c</div>
  <div class="class1-s134">c</div>
  <div c="zclass1-s1">c</div>
  <div>c</div>
</root>

There is an option. We select first by starts-with and then count the number of characters:
Or if you really want regular expressions, then:
/root/div[matches(normalize-space(@class), '^class1..$')]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question