Python Selenium Date Picker

岁酱吖の 提交于 2019-12-25 09:30:20

问题


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']")

it cant find the element

when i use this as the paramater it works

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.

can you guys help me out ?

<!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>

回答1:


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[contains(@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.



来源:https://stackoverflow.com/questions/44455277/python-selenium-date-picker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!