Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xpath - Selecting attributes using starts-with

I am trying to write an xpath expression that selects all div tags that have an attribute id that start with CompanyCalendar. Below is a snippet of the HTML that I am looking at:

<td class="some class" align="center" onclick="Calendar_DayClicked(this,'EventCont','Event');">
        <span class="Text"></span>
        <div id="CompanyCalendar02.21" class="Pop CalendarClick" style="right: 200px; top: 235px;"></div>

There are multiple divs that have an id like CompanyCalendar02.21 but for each new month in the calendar, they change the id. For example, the next month would be CompanyCalendar02.22. I would like to be able to select all of the divs that are equal to CompanyCalendar*

I am rather new at this so I was using some example off the net to try and get my xpath expression to work but to no avail. Any help would be greatly appreciated.

like image 933
Marek Avatar asked Oct 14 '14 17:10

Marek


People also ask

How do I select the first child in XPath?

The key part of this XPath is *[1] , which will select the node value of the first child of Department .

What will be the XPath expression to select?

XPath uses path expressions to select nodes or node-sets in an XML document. The node is selected by following a path or steps.


1 Answers

I am trying to write an xpath expression that selects all div tags that have an attribute id that start with CompanyCalendar.

The following expression is perhaps what you are looking for:

//div[starts-with(@id,'CompanyCalendar')]

What it does, in plain English, is

Return all div elements in the XML document that have an attribute id whose attribute value starts with "CompanyCalendar".

like image 75
Mathias Müller Avatar answered Oct 24 '22 02:10

Mathias Müller