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

Select item fro Button Dropdown List

9 Answers 271 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chaitanya
Top achievements
Rank 1
Chaitanya asked on 23 May 2014, 11:28 AM
    Hi,
I want to select particular item for the button DropDown list .
Please suggest me suitable way to select.

Find.ByXPath<HtmlButton>("/html/body/div/div[2]/div/form/div/div/div/button").Click();

HtmlOrderedList listitem = Find.ByXPath<HtmlOrderedList>("/html/body/div/div[2]/div/form/div/div/div/ul/li[5]/a");
listitem.Click();

Regards,
Chaitanya

9 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 27 May 2014, 10:08 AM
Hello Chaitanya,

Thank you for contacting us.

I am not sure if I understand you correctly. What exactly do you want to click?

Do you want to click an HtmlButton which opens a drop down and then select an item?

Please send us a screen shot of the drop down and its DOM tree so I can write you the code.

Another thing is that we don't recommend using XPath. Even a small change in your application will change the XPath and the test will fail.

Here is an example code:

HtmlSelect mySelect = ActiveBrowser.Find.ByName<HtmlSelect>("cars");
mySelect.SelectByText("Fiat");

Hope to hear from you soon.


Regards,
Boyan Boev
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Chaitanya
Top achievements
Rank 1
answered on 27 May 2014, 10:24 AM
Thank you Boyan ,

Just want to know more about the difference between Click(); function and MouseClick(MouseClickType,LeftClick);

Thanking you in anticipation.

Regards,Chaitanya



0
Boyan Boev
Telerik team
answered on 27 May 2014, 12:27 PM
Hello Chaitanya,

Click() method invokes the click event of the element directly into the DOM.

MouseClick() method simulates a real click. It acts in the same way as a real user. It will move the mouse and click the element.

Hope this helps.

Regards,
Boyan Boev
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Chaitanya
Top achievements
Rank 1
answered on 27 May 2014, 01:02 PM
Hi Boyan,

Thank for the early reply.
Please help me with the DOM structure .
I want to click unorderedlist member CREATE in the following and also what is the best way to iterate from outer div to inner div .

<div class="aaa">
<div id="ms">
<div id="ln" class="open">
<div id="lne" class="">
<i class="ffba"></i>
</div>
<div class="lni">
<ul class="fl">
<li class="sh">
<h3 data-toggle="collapse" data-target="#list-menu" class="collapsed" id="h3list-menu">
<div class="cc">
<i class="ffcd"></i>
</div>
List
</h3>
<ul id="lm" class="csl">
<li>
<a name="">Members</a>
</li>
<li>
<a name="")">Groups</a>
</li>
</ul>
</li>
<li class="sh">
<h3 data-toggle="collapse" data-target="#create-menu" class="collapsed" id="h3create-menu">
<div class="cc">
<i class="ffcd"></i>
</div>
Create
</h3>
<ul id="cm" class="csl">
<li>
<a name="create-menu">Member</a>
</li>
<li>
<a name="create-menu">Group</a>
</li>
</ul>
</li>
<li class="sh">
<h3 data-toggle="collapse" data-target="#affiliates-menu" class="collapsed" id="h3affiliates-menu">
<div class="cc">
<i class="ffdm"></i>
</div>
Affiliates
</h3>
<ul id="affiliates-menu">
<li>
<a name="affiliates-menu">Affiliate Types</a>
</li>
<li>
<a name="affiliates-menu">Commission Types</a>
</li>
<li>
<a name="affiliates-menu">Affiliates</a>
</li>
</ul>
</li>
</ul>
</div> <!-- .left-nav-inner -->
</div><!-- #left-nav --
0
Boyan Boev
Telerik team
answered on 28 May 2014, 12:40 PM
Hi Chaitanya,

As I can see in the DOM tree CREATE along with Member and Group are in a single list item (i.e. the are a single element). It should be also in a separate li.

The only way how you can find it to locate h3 tag with text content CREATE.

HtmlControl h3 = ActiveBrowser.Find.ByContent<HtmlControl>("CREATE");
h3.Click();

If it in a separate list item (<li>CREATE</li>):

HtmlListItem createItem = ActiveBrowser.Find.ByExpression<HtmlListItem>("InnerText=CREATE");
createItem.Click();

Hope this helps.

Regards,
Boyan Boev
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Chaitanya
Top achievements
Rank 1
answered on 29 May 2014, 09:22 AM
Hi Boyan,

That doesn't worked.
i'm getting null value for the h3 as well as for createItem in debug mode (using breakpoint).

Do i have to go from top to bottom iterating each and every html  element to reach the desired element also do we use app.config file in the project for using Database connections in the project.

Regards,Chaitanya
0
Boyan Boev
Telerik team
answered on 02 Jun 2014, 12:11 PM
Hi Chaitanya,

Are you using the the code against the same html you have sent me. The code works against the code you have sent me (even it has a big amount of validating errors).

Can you please record a quick video using Jing to demonstrate the exact steps you take? 

Hope to hear form you soon.

Regards,
Boyan Boev
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Austin
Top achievements
Rank 1
answered on 21 Sep 2018, 12:14 PM
I wants to click on drop down list icon and select(click values) based on index number, value or visible text.
I am able to locate element click over it, but not sure how to select value by above criteria. 

Element drop_down =  Find.ByXPath("//div[@class='k-edit-form-container']//span[@class='k-select']"); 
ActiveBrowser.Actions.Click(drop_down); // click and opens drop down

drop_down.selectByText("company") // not working.

what is the proceedure to acheive it with test studio. 
0
Elena
Telerik team
answered on 21 Sep 2018, 02:12 PM
Hello Austin,

Thank you for reaching us out. 

Probably the list with items which the drop down contains appears dynamically in the DOM tree when the drop down is toggled. To update the current state of the DOM during execution you will need to refresh it. Please try inserting the following line of code between the toggle action and the one which selects the item from drop down: 

this.ActiveBrowser.RefreshDomTree();

Alternatively, if the SelectByText is still not working, you could try to locate the element to select in the DOM tree - it will probably be a ListItem with certain text content - and directly click on it. 

In case you will need further assistance, please share the DOM tree of the page with drop down at the moment when that is opened to select an item. 

Thanks in advance! 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
Chaitanya
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Chaitanya
Top achievements
Rank 1
Austin
Top achievements
Rank 1
Elena
Telerik team
Share this question
or