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"
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
0
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:
Let me know if this helps.
Regards,
Boyan Boev
Telerik
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
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:
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.":
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
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
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
0
0
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:
Hope this helps.
Regards,
Boyan Boev
Telerik
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
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:
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.)
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
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
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