Need to double click to show drop down

9 posts, 0 answers
  1. Lim
    Lim avatar
    16 posts
    Member since:
    Aug 2010

    Posted 19 Aug 2010 Link to this post

    I have two drop down boxes: dd1and dd2.  dd2 starts of being disable and has no value.  dd2 is populated dynamically based on values selected in dd1.  dd2 will be enabled once the values are populated.  However when I try to open dd2 after I select a value from dd1 it requires 2 clicks (or a double click) using WebAii.  If I do this manually I only require 1 click.  

    So why do I need to double click dd2?

    Some things that I've tried:
    1/ added a Thread.sleep(1000) before clicking on dd2.  This didn't work.
    2/ added MouseHover before I did the click on dd2.  That didn't work either.
    3/ used a while loop to check that dd2 was enabled otherwise sleep(1000).  That didn't work.  

    var keyComboBox = app.FindName<ComboBox>("dd1");
    keyComboBox.User.Click();
    keyComboBox.Refresh();
    keyComboBox.SelectByText("Sport");
     
    var valueComboBox = app.FindName<ComboBox>("dd2");     
    valueComboBox.User.Click(MouseClickType.LeftDoubleClick);
    valueComboBox.Refresh();
    valueComboBox.SelectByText("Football");



  2. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 19 Aug 2010 Link to this post

    Hi Lim,

    Thank you for the question.

    The first approach I'd give a go is to wait until my control gets in needed condition. That will avoid any need of Sleep() calls or the loop you tried as well. Here is some code from our samples coming with the distribution:

    //
    // Wait for the guidance to be fully visible.
    //
    // In this application they use the Opacity of the
    // "GuidanceCanvas" to show/hide the guidance.
    Canvas guidanceCanvas = app.FindName<Canvas>("GuidanceCanvas");
    guidanceCanvas.Wait.For(canvas => canvas.Opacity == 1);
     
    guidanceCanvas.Refresh();
     
    // Make sure we got the correct # of guidance popups
    // The application pops 15 overlays on top
    IList<FrameworkElement> guidanceOverlays = guidanceCanvas.Find.AllByType("GuidanceOverlay");
    Assert.IsTrue(guidanceOverlays.Count == 15);
     
    // Now hide the guidance
    app.FindName("guideButton").User.Click();
    // Wait for the guidance to be hidden
    guidanceCanvas.Wait.For(canvas => canvas.Opacity == 0);

    Just to clarify on your test, after you get the combobox you need to click and then call .Refresh() since you need the drop down to get open, is that correct? If so please use the same Wait.For approach to sync the test with the application and make sure the drop down is open. This will also refresh the control internally.

    Can you please give that a go and let us know whether that helps?

    Greetings,
    Konstantin Petkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Lim
    Lim avatar
    16 posts
    Member since:
    Aug 2010

    Posted 19 Aug 2010 Link to this post

    Hi Konstantin,
    Thanks for the quick response.  The Refresh part is working...but from my experimentation only if it is a double click.  If it is a single click then it doesn't work.  

    I'm not familiar with the syntax.  I tried adding a Wait.For e.g. 
    valueComboBox.Wait.For(combobox => combobox.IsEnabled);

    but actually there isn't a IsEnabled property for combobox.  So I'm not sure how I could check that the control is enabled.  

    Also I should mention that these are Silverlight 4 controls.  
  4. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 19 Aug 2010 Link to this post

    Hello Lim,

    There is an IsEnabled property of the ComboBox however the Wait.For() method needs a FrameworkElement predicate. You will need to cast it to ComboBox (use .As<ComboBox>() syntax) to get the ComboBox properties within the predicate.

    Best wishes,
    Konstantin Petkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Lim
    Lim avatar
    16 posts
    Member since:
    Aug 2010

    Posted 19 Aug 2010 Link to this post

    Thanks for that.  I think I've worked out why I need a second click.  I'm not sure if this is a bug or if I'm doing this wrong.  

    To select the value from the dd1 I'm using 
    dd1.SelectByText("somevalue");

    this selects the value BUT doesn't close the drop down box.  So basically what you end up with is that the value is selected the but drop down list is still displayed. If you did this manually you would click a value in the drop down list and then the list will close.  So that is why I need the extra click.  

    Can I select a item using Click?  Or select a value from a drop down some way that would close the drop down list?

  6. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 19 Aug 2010 Link to this post

    Hi Lim,

    There are a few other approaches you can try to select the item in combobox. You can for example find the item by its text and call .User.Click() on that or simply change the SelectedIndex. I think the code from the SelectItem.Execute() method in WebUI Test Studio ComboBox Translator will help you with the API:

    public override void Execute(SilverlightApp autoHost)
    {
        ComboBox cb = ((FrameworkElement)this.Targets[this.PrimaryTargetKey]).As<ComboBox>();
        if (cb == null)
            throw new InvalidOperationException("Invalid target for step");
     
        if (cb.Items.Count == 0)
            cb.Refresh();
     
        if (this.SimulateRealUser)
        {
            if (this.SelectMode == ComboBoxSelectionMode.ByIndex)
            {
                cb.Items[this.BindData<int>("SelectedIndex")].User.Click();
            }
            else
            {
                FindStrategy oldStrategy = cb.Find.Strategy;
                try
                {
                    cb.Find.Strategy = FindStrategy.WhenNotVisibleReturnNull;
     
                    TextBlock block = cb.Find.ByText(this.BindData<string>("SelectedText"));
                    if (block != null)
                    {
                        ComboBoxItem item = block.Parent<ComboBoxItem>();
                        item.EnsureClickable();
                        item.User.Click();
                    }
                }
                finally
                {
                    cb.Find.Strategy = oldStrategy;
                }
            }
        }
        else
        {
            cb.SelectedIndex = this.BindData<int>("SelectedIndex");
        }
    }

    You can replace BindData calls with SelectedIndex/Text with the actual values you run your test with.

    Greetings,
    Konstantin Petkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Lim
    Lim avatar
    16 posts
    Member since:
    Aug 2010

    Posted 19 Aug 2010 Link to this post

    Ah yes! That makes sense now.  Thanks for your help. 
  8. suni
    suni avatar
    1 posts
    Member since:
    Aug 2010

    Posted 03 Sep 2010 Link to this post

    Hi


    I need help to select the item with the help of its name or value  in dropdown list with its Id.

    regards,
    suni
  9. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 08 Sep 2010 Link to this post

    Hello Suni,

    We will need more information about the exact control you are trying to automate to help you further. Can you please submit another ticket and elaborate more on you scenario there? Thank you!

    Regards,
    Konstantin Petkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top