Set Attribute Value and Click

Best practices, code snippets for common functionality, examples, and guidelines.
theraviz
Posts: 72
Joined: Sun Apr 14, 2019 9:46 am

Set Attribute Value and Click

Post by theraviz » Mon Jun 22, 2020 11:41 am

Hello,

I wanted to set a date on a Calendar Control. Montha and Year values are drop down and Date is an A Tag control.

Using the below code I am able to set the month and year properly but after that I have to set the date and then click on the date field.

Problem is setting the date value and clicking on that date.


Report.Log(ReportLevel.Info, "Set value", "Setting attribute TagValue to '1' on item 'selecttagInfo'.", CalMonth);
CalMonth.FindAdapter<SelectTag>().Element.SetAttributeValue("TagValue", _month);
Report.Log(ReportLevel.Info, "Set value", "Setting attribute TagValue to '2020' on item 'selecttagInfo1'.", CalYear);
CalYear.FindAdapter<SelectTag>().Element.SetAttributeValue("TagValue", _year);
Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'atagInfo' at 20;12.", calDate);
CalDate.FindAdapter<ATag>().Element.SetAttributeValue("TagValue", _date);

Here there is no way to perform something like this.

CalDate.FindAdapter<ATag>().Element.SetAttributeValue("TagValue", _date).Click()

or something like

Mouse.Click(CalDate.FindAdapter<ATag>().Element.SetAttributeValue("TagValue", _date);

How to make a click even on the "CalDate" after performing the action mentioned in bold?

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

Re: Set Attribute Value and Click

Post by odklizec » Mon Jun 22, 2020 12:14 pm

Hi,

Use something like this then:

Code: Select all

ATag elementToSetAndClick = CalDate.FindAdapter<ATag>().Element;
elementToSetAndClick.SetAttributeValue("TagValue", _date);
elementToSetAndClick.Click();
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