繁体   English   中英

WebDriver获取最后一个日历日

[英]WebDriver get last calendar day

我需要获取日历中当前月份的最后一天: 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>

和截图


在此处输入图片说明

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

由于表中最后一行的末尾还有另一个td元素,因此您需要排除将该元素与其他元素区分开的类->“ ui-datepicker-other-month”

给定您的示例,您可以尝试:

WebElement lastDay = driver.findElement(By.xpath("((//table//tr)[last()]//td[not (contains(@class, 'ui-datepicker-other-month'))])[last()]"));

如果您想查看31:

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

这是所有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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM