Forum Discussion

GradelinkQA's avatar
GradelinkQA
New Contributor
3 years ago

How can I select a value from a web dropdown menu dynamically based on ID or textContent?

I have a particular web page (built largely in Angular) that has a dropdown menu. The dropdown menu contains several dozen entries that correspond to particular times of day separated by 15-minute intervals. I also have a text label that indicates what time it currently is.

 

What I am attempting to do is to create a keyword test in which the test dynamically determines which value to select from the dropdown menu based on what time the web page thinks it is. In the screenshot above, the text reads "Current school time 2:51PM" and the value "3:00PM" should be selected from the dropdown menu. Currently I'm attempting to do this entirely as a keyword test since TestComplete documentation indicated that was possible.

 

I have already created a simple script that reads the value of the text label and plays with the numbers according to some business rules in order to determine the appropriate value to select from the dropdown menu. The difficulty I am running into is that I can't seem to find the appropriate object property/method to use in order to actually "set" the value of the dropdown menu. I already know that if I run the method hasChildNodes() on the dropdown menu the value is True and if I run childNodes() it returns [NodeList] - both of which indicate TestComplete recognizes there are individual values within the dropdown menu. I've even tried contentText() which returns every value in the menu as a single massive string. However I have not been able to find an appropriate method for 'selecting' a value.

 

If I already know the value I'm looking for based on my script, then what I want to do is select the corresponding value in the dropdown menu. I tried finding a method in order to select a node in the dropdown menu by searching for the appropriate textContent but that didn't seem to work.

 

What am I doing wrong? Is there a "pattern" for how these types of menus should be accessed? Which methods/properties are appropriate in this kind of scenario?