Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HtmlUnit get element by class name containing string [duplicate]

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) ?

like image 456
spark problems Avatar asked Sep 17 '25 08:09

spark problems


1 Answers

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

//div[contains(@class, 'date')]
like image 95
Andersson Avatar answered Sep 19 '25 16:09

Andersson