Xpath - Selecting attributes using starts-with

若如初见. 提交于 2019-12-30 17:16:21

问题


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.


回答1:


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".



来源:https://stackoverflow.com/questions/26366391/xpath-selecting-attributes-using-starts-with

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!