gpt4 book ai didi

java - WebDriver 获取最后一个日历日

转载 作者:行者123 更新时间:2023-12-02 04:29:01 24 4
gpt4 key购买 nike

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

最佳答案

由于表中最后一行的末尾有另一个 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());

关于java - WebDriver 获取最后一个日历日,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31740793/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com