Forum Discussion

nish_b's avatar
nish_b
Contributor
6 years ago

[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 overwr...
  • nish_b's avatar
    nish_b
    6 years ago

    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