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

Cusomize step in code - Click on element specific id

7 Answers 43 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 27 May 2014, 09:14 PM
Hi,

We need some assistance customizing a step in code to click on a specific element that contains a specific id

Here is what we tried, but keep getting "object reference not set to an instance of an object"

// Click 'Gear_ico'
HtmlControl gear = Pages.MainEditPage.Gear_ico.Find.ByAttributes<HtmlControl>("id=codelookup_STD_RECEIPT_DELIVERY");
gear.Click(false);

7 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 29 May 2014, 06:10 AM
Hi Jeff,

Thank you for contacting us.

Please double check whether the element with id "codelookup_STD_RECEIPT_DELIVERY" is exactly under MainEditPage.Gear_ico, if not you can use only ActiveBrowser.Find...

We also have a method which finds elements by ID:

HtmlControl gear = ActiveBrowser.Find.ById<HtmlControl>("codelookup_STD_RECEIPT_DELIVERY");

Let me know if this helps.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Justin
Top achievements
Rank 1
answered on 29 May 2014, 12:59 PM
Jeff and I worked together on this project, and I had a question in regards to what the actual element is. The Gear Image/Icon is in the DOM as a "i" tag. I was wondering what type of HtmlElement this is?  Because I was able to work with it using the generic control (HtmlControl) to find with the gear but I was not able to find with an "Htmlimage" control for example.

Also After exhausting my efforts to find the Control the way that Jeff had described, I ended up drilling down into the HtmlTableCell where the control was actually located and finding it that way. But I would rather like to just find it in the right without having to drill down if that is at all possible. Here is How I did it:
01.htmltable _table = docsection.find.byattributes<htmltable>("class=tblfields");           
02.int rowcount = _table.rows.count;
03.for (int rowno = 0; rowno < rowcount; rowno++)
04.{
05.    int cellcount = _table.rows[rowno].cells.count;               
06.    var cells = _table.rows[rowno].cells;
07.    for (int cellno = 0; cellno < cellcount; cellno++)
08.    {
09.        htmltablecell thecell = _table.rows[rowno].cells[cellno];
10.        htmlcontrol gear = thecell.find.byexpression<htmlcontrol>("id=codelookup_std_" + fieldname);              
11.        if (gear != null)
12.        {
13.            string type = gear.gettype().tostring();
14.            gear.click();
15.        }
16.    }
17.}


NOTE: I was doing all of this in a class, separate from the actual Test... I Know how to reference the Folder and the Class.
PS: "ActiveBrowser" Does not exist in the current context when I try  to use it in my class. Here are the references I use and I have these referenced in the reference "folder.":
01.using System;
02.using System.Collections.Generic;
03.using System.Linq;
04.using System.Text;
05.using System.Threading.Tasks;
06. 
07.using ArtOfTest.Common.UnitTesting;
08.using ArtOfTest.WebAii.Core;
09.using ArtOfTest.WebAii.Controls.HtmlControls;
10.using ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;
11.using ArtOfTest.WebAii.Design;
12.using ArtOfTest.WebAii.Design.Execution;
13.using ArtOfTest.WebAii.ObjectModel;
14.using ArtOfTest.WebAii.Silverlight;
15.using ArtOfTest.WebAii.Silverlight.UI;
16.using Telerik.TestingFramework.Controls.KendoUI;
17.using Telerik.WebAii.Controls.Html;
18.using Telerik.WebAii.Controls.Xaml;
0
Boyan Boev
Telerik team
answered on 02 Jun 2014, 12:15 PM
Hi Justin,

Please send me a screen shot of the DOM tree so I can review your code and find a more reliable solution (if any).

Looking forward to hearing from you.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Justin
Top achievements
Rank 1
answered on 02 Jun 2014, 12:52 PM
Here is the Dom:
( was hope to Search used the Id mainly, but it would not be bad to use the class also)
0
Boyan Boev
Telerik team
answered on 04 Jun 2014, 08:18 AM
Hi Justin,

The <i> tag defines a part of text in an alternate voice or mood. The content of the <i> tag is usually displayed in italic. This tag is deprecated and usually not used, this functionality is achieved in the CSS.

The only way is to iterate through all cells, here is another code:

HtmlTable table = ActiveBrowser.Find.ByAttributes<HtmlTable>("class=tblFields");
            foreach (HtmlTableRow row in table.Rows)
            {
             
                foreach (HtmlTableCell cell in row.Cells)
                   {
                     
                    HtmlControl gear = cell.Find.ById<HtmlControl>("codelookup_STD_STATE");
                    if(gear != null)
                    {
                        gear.MouseClick();
                    }
                }
              }     
                
             
            }

Hope this helps.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Justin
Top achievements
Rank 1
answered on 04 Jun 2014, 12:18 PM
Thank you for your help... I like the way I did it, but both will work so I'm not to concerned.
I have one other question related to this topic:

When you said that we could use the following code:
HtmlControl gear = ActiveBrowser.Find.ById<HtmlControl>("codelookup_STD_RECEIPT_DELIVERY");

Doesn't this piece of code take longer then looping through the table, because now it is looking at all the elements on the webpage that have that particular attribute within an HtmlControl? (True or False, and could you please explain if its better to use the above code or just simply loop through the table as I was originally doing.)



0
Boyan Boev
Telerik team
answered on 09 Jun 2014, 07:13 AM
Hi Jeff,

Yes you are right. Looping through the table should be faster in theory.

If you need further help, please let us know.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Jeff
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Justin
Top achievements
Rank 1
Share this question
or