Python Selenium日期选择器 [英] Python Selenium Date Picker

查看:108
本文介绍了Python Selenium日期选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取日历上的当前活动日期。
当我使用此功能时:

Im trying to get the current active day on the calendar. when i use this:

driver.find_element_by_xpath("//a[@class='ui-state-default ui-state-highlight ui-state-active']")

找不到元素

当我将其用作参数时

driver.find_element_by_xpath(".//*[@id='ui-datepicker-div']/table/tbody/tr[2]/td[6]/a")

但是我认为这是静态的,这就是为什么我不能用它来寻找活动日的原因。

But i believe that is static which is why i cant use it to look for the active day.

你们可以帮我吗?

<!DOCTYPE html>
<html>
<head>
<body onload="if(typeof(window.parentOpeningScript)=='function'){ parentOpeningScript(); };">
<script type="text/javascript">
<div id="floatingMenuDiv" data-role="header" data-id="persistheader" data-position="fixed">
<div id="printPageHeader" class="printOnly">
<div id="primaryContainer" class="clr" style="margin-top: 100px;">
<div id="copyrightMessage" class="clr">
<ul id="ui-id-1" class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content ui-corner-all" tabindex="0" style="display: none;"></ul>
<div id="ui-datepicker-div" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" style="position: absolute; top: 278.767px; left: 443.133px; z-index: 1; display: block;">
<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix ui-corner-all">
<table class="ui-datepicker-calendar">
<thead>
<tbody>
<tr>
<tr>
<td class=" ui-datepicker-week-end " data-handler="selectDay" data-event="click" data-month="5" data-year="2017">
<td class=" " data-handler="selectDay" data-event="click" data-month="5" data-year="2017">
<td class=" " data-handler="selectDay" data-event="click" data-month="5" data-year="2017">
<td class=" " data-handler="selectDay" data-event="click" data-month="5" data-year="2017">
<td class=" " data-handler="selectDay" data-event="click" data-month="5" data-year="2017">
<td class=" ui-datepicker-days-cell-over ui-datepicker-current-day ui-datepicker-today" data-handler="selectDay" data-event="click" data-month="5" data-year="2017">
<a class="ui-state-default ui-state-highlight ui-state-active ui-state-hover" href="#">9</a>
</td>
<td class=" ui-datepicker-week-end " data-handler="selectDay" data-event="click" data-month="5" data-year="2017">
</tr>
<tr>
<tr>
<tr>
</tbody>
</table>
<div class="ui-datepicker-buttonpane ui-widget-content">
</div>
</body>
</html>


推荐答案

没有看到原始的HTML代码,这有点一个推定答案,但应该可以:

Without seeing the original HTML code this is a bit of a presumptive answer, but should work:

driver.find_element_by_xpath( .//*[@ id ='ui-datepicker-div'] / table / tbody / tr / td / a [包含(@class,'ui-state-active')])

此将在该表的任何行中找到第一个锚元素。您可以进一步缩小范围,但这可以完成您想要的工作。

This will find the first anchor element within any row within that table. You could narrow this down further still, but this should accomplish what you're looking to do.

这篇关于Python Selenium日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆