Home > Blockchain >  Select date from calendar in selenium VBA
Select date from calendar in selenium VBA

Time:11-23

I am using selenium in VBA and I have solved similar issue related to calendar but I am stuck on that calendar (I am sure it is related to javascript) Here is the outer HTML of the calendar

<tr><td style="FONT-WEIGHT: bold; PADDING-BOTTOM: 5px; PADDING-TOP: 5px; BACKGROUND-COLOR: honeydew" valign="top" align="center" colspan="4"><table style="WIDTH: 632px" cellspacing="0" cellpadding="0"><tbody><tr><td style="WIDTH: 140px; PADDING-TOP: 10px" valign="top" align="center"><span id="ctl00_ContentPlaceHolder1_Label5" style="display:inline-block;width:125px;">Date</span> <span id="ctl00_ContentPlaceHolder1_Label14" style="color:Red;font-weight:bold;">*</span></td><td style="PADDING-RIGHT: 5px; PADDING-TOP: 10px" valign="middle" align="right"><table id="ctl00_ContentPlaceHolder1_Calendar_Receipt" cellspacing="0" cellpadding="2" title="Calendar" border="0" style="width:276px;height:166px;font-weight:bold;font-size:X-Small;font-family:Verdana;color:Black;border-width:1px;border-style:solid;border-color:White;background-color:White;border-collapse:collapse;">
        <tbody><tr><td colspan="7" style="background-color:White;border-color:Black;border-width:4px;border-style:solid;"><table cellspacing="0" border="0" style="color:#333399;font-family:Verdana;font-size:12pt;font-weight:bold;width:100%;border-collapse:collapse;">
            <tbody><tr><td valign="bottom" style="color:#333333;font-size:8pt;font-weight:bold;width:15%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','V7852')" style="color:#333333" title="Go to the previous month">July</a></td><td align="center" style="width:70%;">August 2021</td><td align="right" valign="bottom" style="color:#333333;font-size:8pt;font-weight:bold;width:15%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','V7914')" style="color:#333333" title="Go to the next month">September</a></td></tr>
        </tbody></table></td></tr><tr><th align="center" abbr="Sunday" scope="col" style="font-size:8pt;font-weight:bold;">Sun</th><th align="center" abbr="Monday" scope="col" style="font-size:8pt;font-weight:bold;">Mon</th><th align="center" abbr="Tuesday" scope="col" style="font-size:8pt;font-weight:bold;">Tue</th><th align="center" abbr="Wednesday" scope="col" style="font-size:8pt;font-weight:bold;">Wed</th><th align="center" abbr="Thursday" scope="col" style="font-size:8pt;font-weight:bold;">Thu</th><th align="center" abbr="Friday" scope="col" style="font-size:8pt;font-weight:bold;">Fri</th><th align="center" abbr="Saturday" scope="col" style="font-size:8pt;font-weight:bold;">Sat</th></tr><tr><td align="center" style="color:#999999;width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7876')" style="color:#999999" title="July 25">25</a></td><td align="center" style="color:#999999;width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7877')" style="color:#999999" title="July 26">26</a></td><td align="center" style="color:#999999;width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7878')" style="color:#999999" title="July 27">27</a></td><td align="center" style="color:#999999;width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7879')" style="color:#999999" title="July 28">28</a></td><td align="center" style="color:#999999;width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7880')" style="color:#999999" title="July 29">29</a></td><td align="center" style="color:#999999;width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7881')" style="color:#999999" title="July 30">30</a></td><td align="center" style="color:#999999;width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7882')" style="color:#999999" title="July 31">31</a></td></tr><tr><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7883')" style="color:Black" title="August 01">1</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7884')" style="color:Black" title="August 02">2</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7885')" style="color:Black" title="August 03">3</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7886')" style="color:Black" title="August 04">4</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7887')" style="color:Black" title="August 05">5</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7888')" style="color:Black" title="August 06">6</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7889')" style="color:Black" title="August 07">7</a></td></tr><tr><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7890')" style="color:Black" title="August 08">8</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7891')" style="color:Black" title="August 09">9</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7892')" style="color:Black" title="August 10">10</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7893')" style="color:Black" title="August 11">11</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7894')" style="color:Black" title="August 12">12</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7895')" style="color:Black" title="August 13">13</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7896')" style="color:Black" title="August 14">14</a></td></tr><tr><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7897')" style="color:Black" title="August 15">15</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7898')" style="color:Black" title="August 16">16</a></td><td align="center" style="color:White;background-color:Red;width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7899')" style="color:White" title="August 17">17</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7900')" style="color:Black" title="August 18">18</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7901')" style="color:Black" title="August 19">19</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7902')" style="color:Black" title="August 20">20</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7903')" style="color:Black" title="August 21">21</a></td></tr><tr><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7904')" style="color:Black" title="August 22">22</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7905')" style="color:Black" title="August 23">23</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7906')" style="color:Black" title="August 24">24</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7907')" style="color:Black" title="August 25">25</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7908')" style="color:Black" title="August 26">26</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7909')" style="color:Black" title="August 27">27</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7910')" style="color:Black" title="August 28">28</a></td></tr><tr><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7911')" style="color:Black" title="August 29">29</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7912')" style="color:Black" title="August 30">30</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7913')" style="color:Black" title="August 31">31</a></td><td align="center" style="color:#999999;width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7914')" style="color:#999999" title="September 01">1</a></td><td align="center" style="color:#999999;width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7915')" style="color:#999999" title="September 02">2</a></td><td align="center" style="color:#999999;width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7916')" style="color:#999999" title="September 03">3</a></td><td align="center" style="color:#999999;width:14%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7917')" style="color:#999999" title="September 04">4</a></td></tr>
    </tbody></table> </td></tr></tbody></table></td></tr>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

Can you guide me how to deal with such calendar?

I noticed at these lines the following

<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','0')" style="color:Black" title="January 01">1</a>

The parameter which is '0' represents 01 January 2000 and this number changes to '1' on 02 Jaunuary 2000. Is it possible to go to specific date using such javascript directly?

CodePudding user response:

Induce some wait and you can use either of the following Locator Strategies:

  • XPath:

    //tr/td/a[@title='Go to the previous month' and text()='July']
    
  • Css:

    tr>td>a[title='Go to the previous month']
    
  • Related