Pick a Saturday from a calendar

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
maamer
Posts: 23
Joined: Fri Nov 30, 2018 6:03 pm

Pick a Saturday from a calendar

Post by maamer » Fri Jan 25, 2019 10:50 pm

Hello All,
i ran into a trouble. i am trying to pick a non business day (saturday) from the calendar(in snapshot). given that the calendar tr and td tags change every month. how to uniquely define xpath for this?.
i am trying to do in a user code method in a recording:

string dateday = System.DateTime.Today.Day.ToString();
tdtag todaydate = "/dom[@domain='6012-sbx.btbanking.com']/body/div[7]//table/tbody/tr[4]/td[@innertext='25']//following-sibling/td[@childindex = '6']";
todaydate.click();

since child index of saturday column is always 6.
obviously this will not work tomorrow.. is there any way to insert the dateday variable in the xpath of todaydate something like "td[@innertext=dateday]". i tried "td[@innertext=$dateday]" and it didnot work.

could anyone help me with this.

Thank you.
Attachments
calendar.rxsnp
(764.69 KiB) Downloaded 1 time

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 4653
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Pick a Saturday from a calendar

Post by odklizec » Mon Jan 28, 2019 9:06 am

Hi,

To pass the variable to xpath (in code), you must do it like this:

Code: Select all

tdtag todaydate = "/dom[@domain='6012-sbx.btbanking.com']/body/div[7]//table/tbody/tr[4]/td[@innertext='" + dateday  + "']//following-sibling/td[@childindex = '6']";
BTW, you should also remove all indexes, otherwise, it will fail with day in another row. I would suggest xpath like this:

Code: Select all

tdtag todaydate = "/dom[@domain='6012-sbx.btbanking.com']/body//table/tbody/tr/td[@innertext='" + dateday  + "']//following-sibling/td[@childindex = '6']";
Additionally, using xpath directly in code is a big mistake people often do. You should rather pass the repo element to code via method parameter. So then if the xpath of repo element changes, you don't have to change it at many places in code. Just change it once in repo ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

maamer
Posts: 23
Joined: Fri Nov 30, 2018 6:03 pm

Re: Pick a Saturday from a calendar

Post by maamer » Mon Jan 28, 2019 3:46 pm

Thank you sir, This is awesome.