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

How to find an link button in a listview by the content in listview?

1 Answer 131 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Yulan
Top achievements
Rank 1
Yulan asked on 02 Dec 2010, 11:26 PM
We have listview with edit, delete button.
I record and generate steps to add an element in the listview, then delete the element.

The problem is the delete link button is selected by the location in listview, not related to the content that I added.

followling is the Find Expression:
id=ctl00_ctlLeftMenu1_lvLeftMenu_ctrl0_rptMenuItem_ctl02_lbMenuItem,tagname=a

How can I change the Find Expression to make sure the element to delete is the element that just been added?

Thanks,
Yulan

1 Answer, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 07 Dec 2010, 04:56 PM
Hello Yulan,
      it seems all the "Delete" buttons in your entire list are identical. The Find Logic using ID and tag-name probably fails to find the right one because they all have the same ID. You can tell them apart by using their parent element (probably <li> in your case). Unfortunately the only way to base an element's Find Logic on its parent is by writing the Find Logic yourself in a Coded Step.
 
I assume you're using a List like this:
http://www.w3schools.com/html/html_lists.asp
-->then you have to reach the correct <li> member of your <ul> (List).

The way you can do that depends on what makes each <li> unique. For instance if they look like this:
<li> THIS IS THE NAME <a id="" href=""> Del Button <a> </li>
and the text "THIS IS THE NAME" is the name you gave it (different for each <li>) then you can do this in a Coded Step:
HtmlListItem li = Find.ByExpression<HtmlListItem>("Value=THIS IS THE NAME");
HtmlAnchor delButton = new HtmlAnchor(l.ChildNodes[0]);
delButton.Click(false);
This finds the <li> by its unique feature (the text which you've entered), from there it gets the only child (the delete button) and presses it.

This is a general example - you'll need to figure out exactly how to get the job done in your specific case. If you're having lots of trouble with it - consider providing us with access to this part of your app - we can write it for you.

Here's a tutorial on Find ByExpression which you can check out:
http://www.artoftest.com/support/webaii/topicsindex.aspx?topic=byexpression

I've have a couple of videos (actually one video in two parts) I've recorder explaining how to accomplish something very similar - check it out if you have the time:
Part 1 - http://www.screencast.com/t/vciuJkpml
Part 2 - http://www.screencast.com/t/jWif4eChuL

I hope this helps, let us know if you need help with anything else!

All the best,
Stoich
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
Tags
General Discussions
Asked by
Yulan
Top achievements
Rank 1
Answers by
Stoich
Telerik team
Share this question
or