How to open a dropdown control
I am writing Automation Test for a web appliocation. On a page, there are two controls: Date of Birth and Gender. The Date of Birth is like a Datetimepicker. When it is clicked, a calender shows up. The Gender is a <select> control, a dropdown opens when it is clicked. The picture shows the Source code behind the page. I am writing script to identify the objects and then envoke the right method of the object to perform actions. I need to programatically open the dropdown of these controls and then take a screen shot as objective evidence to show the dropdown opens. I used XPath to identify and get the object on the page and then tried "Click()" and "DropDown()" methods on the object, but neither opened the dropdown control. Can anyone help? Thank you!!
I tried the recording the tests using keyword test but the Gender Dropdown does not open when the recording is on.
After a few tries, I eventually found the solution. The DateTimePicker and the Generder Dropdown are wrapped inside a lot of control containers. The DateTimePicker control has two <Input> and they are inside multiple <div>, I must get the <input> with "class = 'dateTimePicker'" using XPath and then perform click() operation on this control to open the DateTimePicker; the Gender DropDown has multiple <span> controls, I must get the <span> with "Role = 'combobox'". When perform a "Click ()" on this control, it opens the dropdown.
The attached image has the two controls hightlighted in Red. I hope this may help someone who is puzzling on this type of issues.