4

I want to find any elements in the HtmlPage that have a class that contains the word 'date'.

ie i want to match any of the following:

<div class = 'date'> August 13 2017 </div>
<span class = 'pubDate'> August 12 2017 </div>
<div class = 'datePublished'> August 10 2017 </div>

In order to match exactly 'date' I am using the following:

HtmlPage page;
List<HtmlDivision> date = page.getByXPath("//div[@class='date']");
System.out.println(date.get(0));

Which is working correctly.

However, how do I change this (or what else should I use ) in order to be able to match any element that has a class name that contains the word date (case insensitive) ?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
spark problems
  • 55
  • 1
  • 1
  • 8

1 Answers1

5

Try below XPath to match all div elements with attribute class that contains "date":

//div[contains(@class, 'date')]
Andersson
  • 51,635
  • 17
  • 77
  • 129