This is a migrated thread and some comments may be shown as answers.

Unable to select value from ComboBox

4 Answers 130 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Luis
Top achievements
Rank 1
Luis asked on 24 Apr 2015, 04:12 PM

Hi,

 

I can't seem to figure out how can I get TS so select a value from a combobox.

I've tried to record clicking on the combobox button to open it and then clicking on a value, but this does not execute properly.

After searching on the forum and found this thread (http://www.telerik.com/forums/how-to-select-from-drop-down-list) I also tried the following code, but this also doesn't work.

// Enter text 'Audi' in 'Text'
Pages.LusitaniaSimuladorMotore26.Span.Click();
            
HtmlSelect marca = ActiveBrowser.Find.ById<HtmlSelect>("marcas");
                    
marca.SelectByValue("Audi");

 With the above code I can see that the combobox opens, but no value is selected.

The HTML of the page is

<div id="marcas_id_div"><select id="marcas" onchange="javascript:ResetTotais(); ResetVersao(); ResetVeiculoInfo(); GetVersoes(false); CarregarVariaveis(0, 0, this.name);" name="marcas" style="width: 270px; display: none;"><option value=""> </option><option value="Abarth">Abarth </option><option value="Alfa Romeo">Alfa Romeo </option><option value="Aston Martin">Aston Martin </option><option value="Audi">Audi </option><option value="Bentley">Bentley </option><option value="Bmw">Bmw </option><option value="Chevrolet">Chevrolet </option></select><span class="ui-combobox"><input class="ui-state-default ui-combobox-input ui-autocomplete-input ui-widget ui-widget-content ui-corner-left" style="padding: 0 5px; height: 22px;" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true"><a class="ui-button ui-widget ui-state-default ui-button-icon-only ui-corner-right ui-combobox-toggle" tabindex="-1" title="Mostrar Todos Os Itens" role="button" aria-disabled="false" style=""><span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-s"></span><span class="ui-button-text"></span></a></span></div>

 

Please help me.

 

Thanks,

Luis

4 Answers, 1 is accepted

Sort by
0
Luis
Top achievements
Rank 1
answered on 27 Apr 2015, 10:57 AM

Hi,

 I found the current TS documentation that seemed to be able to solve my problem but it didn't work.

What I did was

Element marcasList = ActiveBrowser.Find.ByXPath("/html/body/div[1]/div[1]/form/div[16]/div/div[1]/table/tbody/tr[9]/td/div/span/a");
HtmlControl btnMarcas = marcasList.As<HtmlControl>();
btnMarcas.ScrollToVisible();
btnMarcas.MouseClick();
 
Element comboInput = ActiveBrowser.Find.ById("marcas");
ActiveBrowser.Actions.SelectDropDown(comboInput, "Audi", true);

 

I can see the dropbox is expanded but nothing is selected.

 

Am I missing something?

 

BR,

Luis

 

 

0
Ivaylo
Telerik team
answered on 29 Apr 2015, 11:10 AM
Hello Luis,

The initial code snippet you provided should work like a charm. Here is a short video demonstration (no audio) how this works on my end, using your code.

In order to investigate further we will need to be able to access your application. Would that be possible?

Regards,
Ivaylo
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Luis
Top achievements
Rank 1
answered on 29 Apr 2015, 04:45 PM

Hi  Ivaylo,

 1st of all thank you for your reply.

Due to customer constraints, we are not allowed to give access to the application.

 I tried again running my code snippet and still I couldn't see anything being set in the field. I don't if it make a difference, but the element "select" is disabled (in attach I send you a screen of the page HTML).

One more particularity, is the fact that after this combo, another combo exists to choose the model (based on the choice made in the 1st one). 

 The way I found to interact with this element, is like so

1.//Select Make.
2.HtmlControl btnMarcas = ActiveBrowser.Find.ByXPath("/html/body/div[1]/div[1]/form/div[16]/div/div[1]/table/tbody/tr[9]/td/div/span/a").As<HtmlControl>();
3.btnMarcas.MouseClick();
4.Manager.Desktop.KeyBoard.TypeText("Audi");
5.Manager.Desktop.KeyBoard.KeyPress(Keys.Down);
6.Manager.Desktop.KeyBoard.KeyPress(Keys.Enter);
 

This way I can open the dropdown, type the value (to filter my choices) and then select the 1st one (and only one) in the drop down.

 

So to summarize, I manage to overcome my issue, but if you could tell me what could be causing my first approach not to work, that would be great.

 

BR,

Luis

0
Accepted
Ivaylo
Telerik team
answered on 01 May 2015, 12:44 PM
Hеllo Luis,

On your question:

So to summarize, I manage to overcome my issue, but if you could tell me what could be causing my first approach not to work, that would be great.

I am glad to hear you have managed to overcome this issue. If I knew what is causing your first approach not to work I couldn't ask for access to your application. As you can see from the video provided, the very same approach with your own code is working just fine on my end.

Regards,
Ivaylo
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
Luis
Top achievements
Rank 1
Answers by
Luis
Top achievements
Rank 1
Ivaylo
Telerik team
Share this question
or