user3436891
user3436891

Reputation: 1

How to select value from a dropdown using JScript (not JavaScript) with TestComplete

Currently I'm working on TestComplete automation tool. I'm facing a problem in selecting a value from a dropdown using Jscript. It can done easily in javascript by

document.getElementById("id").options[1].selected=true

I cant do it using JScript'. I've tried

Browsers.Item(btIExplorer).Run("Page URL"); //opening the browser and running a URL
    browser=Aliases.browser; //creating alias of browser object
    page=browser.Page("PageURL"); //creating a page object for the page opened
   page.NativeWebObject.Find("id", "defaultLocationBinder_newOrExisting", "input") // This is the dropdown

I'm not able to find any suitable option to select the options in the dropdown which are given in the <option></option> tags

Upvotes: 0

Views: 2752

Answers (2)

Dmitry Nikolaev
Dmitry Nikolaev

Reputation: 3918

The NativeWebObject.Find method returns a native object while you may want to work with a TestComplete wrapper. Use the Find or FindChild method to get such a wrapper and the Clickitem method to select a specific item.

function test()
{
  var b = Sys.Browser("iexplore");
  b.ToUrl("http://support.smartbear.com/message/?prod=TestComplete");
  var page = b.Page("http://support.smartbear.com/message/?prod=TestComplete");
  var cBox = page.FindChild("ObjectIdentifier", "ddlRequestType", 20);
  cBox.ClickItem("General product question");
}

Upvotes: 0

Gabriel Pita
Gabriel Pita

Reputation: 336

I just wrote this piece of code and was able to do it. Use the selectedIndex to set the option you want.

use the object spy to check the properties/methods you can use with the object.

function loginDropDown()
    {
      var dropDown = Sys.Browser("iexplore").Page("*").FindChild("Name","Select(\"myList\")",10,true)
      dropDown.selectedIndex = 1

    }

Upvotes: 3

Related Questions