WebDriver获取最后一个日历日

时间:2015-07-31 07:45:42

标签: java selenium calendar webdriver

我需要在日历中获取当月的最后一天:http://prntscr.com/7z506w

这是HTML代码:

<table class="ui-datepicker-calendar">
    <thead>
    <tbody>
        <tr>
        <tr>
        <tr>
        <tr>
            <td
                class=" ui-datepicker-week-end ui-datepicker-unselectable ui-state-disabled null"
                title="Cannot choose a date earlier than a previous anchor task or the start date.">
            <td class=" ui-datepicker-unselectable ui-state-disabled null"
                title="Cannot choose a date earlier than a previous anchor task or the start date.">
            <td class=" ui-datepicker-unselectable ui-state-disabled null"
                title="Cannot choose a date earlier than a previous anchor task or the start date.">
            <td class=" ui-datepicker-unselectable ui-state-disabled null"
                title="Cannot choose a date earlier than a previous anchor task or the start date.">
            <td class=" ui-datepicker-unselectable ui-state-disabled null"
                title="Cannot choose a date earlier than a previous anchor task or the start date.">
            <td class=" ui-datepicker-unselectable ui-state-disabled null"
                title="Cannot choose a date earlier than a previous anchor task or the start date.">
            <td
                class=" ui-datepicker-week-end ui-datepicker-unselectable ui-state-disabled null"
                title="Cannot choose a date earlier than a previous anchor task or the start date.">
        </tr>
        <tr>
            <td
                class=" ui-datepicker-week-end ui-datepicker-unselectable ui-state-disabled null"
                title="Cannot choose a date earlier than a previous anchor task or the start date.">
                <span class="ui-state-default">26</span>
            </td>
            <td class=" ui-datepicker-unselectable ui-state-disabled null"
                title="Cannot choose a date earlier than a previous anchor task or the start date.">
                <span class="ui-state-default">27</span>
            </td>
            <td class=" ui-datepicker-unselectable ui-state-disabled null"
                title="Cannot choose a date earlier than a previous anchor task or the start date.">
                <span class="ui-state-default">28</span>
            </td>
            <td class=" ui-datepicker-unselectable ui-state-disabled null"
                title="Cannot choose a date earlier than a previous anchor task or the start date.">
                <span class="ui-state-default">29</span>
            </td>
            <td class=" ui-datepicker-unselectable ui-state-disabled null"
                title="Cannot choose a date earlier than a previous anchor task or the start date.">
                <span class="ui-state-default">30</span>
            </td>
            <td class=" ui-datepicker-days-cell-over null ui-datepicker-today"
                onclick="DP_jQuery_1438322656964.datepicker._selectDay('#FormElement_date_289_input',6,2015, this);return false;">
                <a class="ui-state-default ui-state-highlight ui-state-hover"
                href="#">31</a>
            </td>
            <td class=" ui-datepicker-week-end ui-datepicker-other-month ui-datepicker-unselectable ui-state-disabled"/>
        </tr>
    </tbody>
</table>

截图

enter image description here

那么如何知道它是日历中的最后一个元素,并在Selenium WebDriver中获取它?

2 个答案:

答案 0 :(得分:2)

由于表格中最后一行末尾有另一个td元素,因此您需要排除区分此元素与其他元素的类 - &gt; &#34; UI-日期选择器-其他个月&#34;

根据您的示例,您可以尝试:

System.out.println(lastDay.getText());

如果你想看31:

String[] ar1={"chemicals","biscuits"};
String[] ar2={"1","2"};

adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, ar1);   adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);                                 
your_spinner.setAdapter(adapter);

//to get the selected item position
int x=your_spinner.getSelectedItemPosition();

答案 1 :(得分:0)

这里是所有HTML表格

<table class="ui-datepicker-calendar">
<thead>
<tbody>
<tr>
<tr>
<tr>
<tr>
<tr>
<td class=" ui-datepicker-week-end ui-datepicker-unselectable ui-state-disabled null" title="Cannot choose a date earlier than a previous anchor task or the start date.">
<td class=" ui-datepicker-unselectable ui-state-disabled null" title="Cannot choose a date earlier than a previous anchor task or the start date.">
<td class=" ui-datepicker-unselectable ui-state-disabled null" title="Cannot choose a date earlier than a previous anchor task or the start date.">
<td class=" ui-datepicker-unselectable ui-state-disabled null" title="Cannot choose a date earlier than a previous anchor task or the start date.">
<td class=" ui-datepicker-unselectable ui-state-disabled null" title="Cannot choose a date earlier than a previous anchor task or the start date.">
<td class=" ui-datepicker-days-cell-over null ui-datepicker-today" onclick="DP_jQuery_1438322656964.datepicker._selectDay('#FormElement_date_289_input',6,2015, this);return false;">
<a class="ui-state-default ui-state-highlight ui-state-hover" href="#">31</a>
</td>
<td class=" ui-datepicker-week-end ui-datepicker-other-month ui-datepicker-unselectable ui-state-disabled"/>
</tr>
</tbody>
</table>