1

I have 2 elements on my webpage

element 1 : <div class="DynarchCalendar-day DynarchCalendar-day-othermonth" dyc-type="date" unselectable="on" dyc-date="19960429">

element 2 : <div class="DynarchCalendar-day" dyc-type="date" unselectable="on" dyc-date="19960501">

If i do

List<WebElement> DynarchCalendar_day  = driver.findElements(By
                    .cssSelector("div.DynarchCalendar-day"));

I will get list of WebElements containing both element 1 and element 2

If i do

List<WebElement> DynarchCalendar_day  = driver.findElements(By
                    .cssSelector("div.DynarchCalendar-day.DynarchCalendar-day-othermonth"));

I will get list of WebElements containing only element 1

What can i do to get Element 2 only ?

4

2 回答 2

1

You could use a not to find divs with DynarchCalendar-day but not DynarchCalendar-day-othermonth.

The css-selector would be:

"div.DynarchCalendar-day:not(.DynarchCalendar-day-othermonth)"
于 2013-07-11T15:16:39.067 回答
0

Use the :not(), but it doesn't works in old Internet Explorer(7, 8). Also you can use div[class='DynarchCalendar-day']. It looks for exact coincidence.

于 2013-07-14T23:04:09.320 回答