0

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>

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?

YasserKhalil
  • 9,138
  • 7
  • 36
  • 95

1 Answers1

1

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']
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks a lot. Does ExecuteScript support xpath? If so, please give me an example of line of code? – YasserKhalil Nov 23 '21 at 06:43
  • Ii is solved .. Just one point, how to select specific day from the grid of calendar say I want day 15? – YasserKhalil Nov 23 '21 at 06:46
  • Wait, I have to reconstruct the DOM – undetected Selenium Nov 23 '21 at 06:47
  • For _15_ you can try xpath -> `//tr/td/a[@title='August 15' and text()='15']` Css-> `tr > td > a[title='August 15']` – undetected Selenium Nov 23 '21 at 06:52
  • Thanks a lot but the xpath should be dynamic as the date is not fixed. Please have a look as I have updated my question as I noticed something related to the javascript approach. – YasserKhalil Nov 23 '21 at 06:53
  • `doPostBack` don't worry about it. You need to wait for freshness of the DOM. – undetected Selenium Nov 23 '21 at 06:58
  • I mean is there a way to use such number in the parameter I referred to to go directly to the date? Example: The date 27 July 2021 is related to the number '7878' . Can we use doPostBack to directly go to that date? – YasserKhalil Nov 23 '21 at 07:05
  • Nopes, I don't see a relation there. – undetected Selenium Nov 23 '21 at 07:08
  • I tried such a line and worked `.ExecuteScript "javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','7879');"` This goes to the 28 July 2021 but when try to go to another far away date `.ExecuteScript "javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar_Receipt','0');"`, it failed – YasserKhalil Nov 23 '21 at 07:08
  • But the question is how would you relate `28 July 2021` -> `7879` and so on in real time scenarios? – undetected Selenium Nov 23 '21 at 07:09
  • The start point is 0 (01 january 2000) so there must be a way to calculate the correct number. But it seems not to work if the date is not visible on the grid so the idea is not on the right way – YasserKhalil Nov 23 '21 at 07:12