[TestComplete JS] ClickItem() is not working for dropdown
Hi,
I have a web application which has a multi-select dropdown with some values which looks the one in screenshot named dropdown
(Note: There are some values in dropdown but I have overwritten by the highlighter as its not necessary info for this).
My requirement is that I need to click on 1 of the items in the dropdown based on the text. For example, if I have a text named as "Apple" in the dropdown. I want to click on that. I similated the action and converted to script using Record Script. I got the below command for this:
vselect.ClickItem("Apple");
But this is not working. When I re-run this script it throws the error: "Cannot activate the 'Apple' item"
Can you please help?
Hi,
Just wanted to provide an update: I was finally able to resolve the issue. Thought I could describe it here, to help anyone else reading this post.
Issue: Unable to click on dropdown element to select a desired element. The dropdown is on Select type.
Resolution:
Entire select webelement was getting identified but when I try to identify any 1 of the <option> webelements, it never used to identify. It used to return as an object or null.
So, the solution I came up with is to identify the dropdown <select> by using native DOM method in JavaScript. Then use the selectedIndex property to find out the index of the <option> element which is already selected by default and replace it with desired index of the <option> webelement which you want to select.
Example:
let page = Sys.Browser("*").Page("url");
let selectObj = page.contentDocument.querySelector('abc'); //replace with css selector of Select dropdown
//code to get the index of the <option> webelement which needs to be selected
selectObj.selectedIndex=index;
The above statement will select based on the index of the <option> webelement