How can I target the div
elements that have the class "month-table_col"
(selecting by month).
...
<div class="month-table">
<div class="month-table_row">
<div class="month-table_col">Jan</div>
<div class="month-table_col">Feb</div>
<div class="month-table_col">Mar</div>
</div>
<div class="month-table_row">
<div class="month-table_col">Apr</div>
<div class="month-table_col">May</div>
<div class="month-table_col">Jun</div>
</div>
<div class="month-table_row">
<div class="month-table_col">Jul</div>
<div class="month-table_col">Aug</div>
<div class="month-table_col">Sep</div>
</div>
<div class="month-table_row">
<div class="month-table_col">Oct</div>
<div class="month-table_col">Nov</div>
<div class="month-table_col">Dec</div>
</div>
</div>
...
Below is the XPath code used to target the div
elements, for example, to select the div
containing the value 'Nov'.
//div[contains(@class, 'month-table_col') and contains(text(), 'Nov')]
Upon executing the following command in the Google Chrome console,
$x("//div[contains(@class, 'month-table_col') and contains(text(), 'Nov')]")
The result is as follows: an array with one element is returned like this
[div.month-table_col]
0: div.month-table_col
lastIndex:(...)
lastItem:(...)
length: 1
__proto__:Array(0)
Even specifying the index of 1 yields the same outcome as mentioned above.
$x("//div[contains(@class, 'month-table_col') and contains(text(), 'Nov')][1]")
The result obtained is correct, but is there a way to retrieve the element as a tag rather than an array?
Expected output:
<div class="month-table_col">Nov</div>