Hello,
I am working on creating a test where I need to check every checkbox that appears on a page. This page is driven by rule validation from data entered on other pages, so the number of check boxes on the page could vary from 1 to 200 depending on the test case that is being run. The checkboxes are displayed in an HtmlTable, on per body row. The only difference in the id of the checkboxes is the bolded part: uwciRepeater_ctl01_checkBox_Approve. Based on what number it is, it will show ctl00, ctl01, ctl02, etc.
I attempted changing expression in the find logic on the item to remove the ctl01 part and using a Do-While, but this still selects just the first checkbox. I have been attempting different coded steps to no success. I played with the idea of recording a huge if...then statement within the test, but I feel like that would be a large amount of steps and not the most optimal solution. I was wondering if anyone would have an example of a coded step that could solve this issue.
Thank you,
Tyler
I am working on creating a test where I need to check every checkbox that appears on a page. This page is driven by rule validation from data entered on other pages, so the number of check boxes on the page could vary from 1 to 200 depending on the test case that is being run. The checkboxes are displayed in an HtmlTable, on per body row. The only difference in the id of the checkboxes is the bolded part: uwciRepeater_ctl01_checkBox_Approve. Based on what number it is, it will show ctl00, ctl01, ctl02, etc.
I attempted changing expression in the find logic on the item to remove the ctl01 part and using a Do-While, but this still selects just the first checkbox. I have been attempting different coded steps to no success. I played with the idea of recording a huge if...then statement within the test, but I feel like that would be a large amount of steps and not the most optimal solution. I was wondering if anyone would have an example of a coded step that could solve this issue.
Thank you,
Tyler
8 Answers, 1 is accepted
0
Hello Tyler,
this is done fairly easily in code:
I tried this code against this page:
http://www.tizag.com/htmlT/htmlcheckboxes.php
and it worked flawlessly except that checkboxes that are already checked become unchecked.
Also, one thing to consider is that this will not work for checkboxes inside of Frames. Instead you'll need to search directly into a Frame in order to perform the same actions.
i.e. Frame.Find.AllByTagName("Input")...
Best wishes,
Stoich
the Telerik team
this is done fairly easily in code:
foreach
(Element e
in
Find.AllByTagName(
"Input"
))
{
if
(e.InputElementType == InputElementType.CheckBox)
{
HtmlControl hc = e.As<HtmlControl>();
hc.ScrollToVisible();
hc.MouseClick();
}
}
I tried this code against this page:
http://www.tizag.com/htmlT/htmlcheckboxes.php
and it worked flawlessly except that checkboxes that are already checked become unchecked.
Also, one thing to consider is that this will not work for checkboxes inside of Frames. Instead you'll need to search directly into a Frame in order to perform the same actions.
i.e. Frame.Find.AllByTagName("Input")...
Best wishes,
Stoich
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Tyler
Top achievements
Rank 1
answered on 11 Oct 2011, 03:05 PM
Hello Stoich,
Thank you very much for the code - this worked very well. I wanted to let you know this behavior that I saw - when doing hc.MouseClick() I observed that it only checked about 1/2 to 2/3 of the boxes on the page, and it was random in what boxes it checked. I got the solution to work using hc.Click(), so all is good, but I wanted to bring that to your attention in case there is any sort of bug with MouseClick().
Thanks again for the quick response,
Tyler
Thank you very much for the code - this worked very well. I wanted to let you know this behavior that I saw - when doing hc.MouseClick() I observed that it only checked about 1/2 to 2/3 of the boxes on the page, and it was random in what boxes it checked. I got the solution to work using hc.Click(), so all is good, but I wanted to bring that to your attention in case there is any sort of bug with MouseClick().
Thanks again for the quick response,
Tyler
0
Hello Tyler,
interesting. MouseClick() attempts to simulate a real user click on an element. On the other hand Click() works directly on the DOM structure of the app. Perhaps the clicks are occurring in very rapid succession. This could leads to problems with the simulate real click (i.e. MouseClick() ) since a real user would not be able to click around to rapidly.
If you're interested in getting to the bottom of this you can introduce a fixed delay in the test and check out whether that resolves the issue.
A fixed delay in code will look like this:
You can put this like before you invoke the MouseClick() function.
Regards,
Stoich
the Telerik team
interesting. MouseClick() attempts to simulate a real user click on an element. On the other hand Click() works directly on the DOM structure of the app. Perhaps the clicks are occurring in very rapid succession. This could leads to problems with the simulate real click (i.e. MouseClick() ) since a real user would not be able to click around to rapidly.
If you're interested in getting to the bottom of this you can introduce a fixed delay in the test and check out whether that resolves the issue.
A fixed delay in code will look like this:
System.Threading.Thread.Sleep(1000);
//Fixed delay - takes miliseconds as a parameter
Regards,
Stoich
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Muhammad
Top achievements
Rank 1
answered on 04 Nov 2014, 02:46 PM
Hi Stoich,
can you please translate in vb? because mine project is in vb.
Thanks you so much
can you please translate in vb? because mine project is in vb.
Thanks you so much
0
Muhammad
Top achievements
Rank 1
answered on 04 Nov 2014, 02:47 PM
can you please translate in vb?
0
Hi Muhammad,
You can use our free code converter to convert code between C# and VB.
Regards,
Cody
Telerik
You can use our free code converter to convert code between C# and VB.
Regards,
Cody
Telerik
0
Jonathan
Top achievements
Rank 1
answered on 08 Nov 2015, 03:27 AM
Hi,
I have a follow up question. I only want to check all the checkboxes where the id = gridUserRoleList and the checkbox was unchecked. Any help in C# would be appreciated. Thanks!
0
Hello Jonathan,
I am providing you below the code you've requested:
Regards,
Ivaylo
Telerik
I am providing you below the code you've requested:
var checkBoxes = Manager.ActiveBrowser.Find.AllByExpression<HtmlInputCheckBox>(
"id=gridUserRoleList"
).Where((cb) => !cb.Checked);
Manager.Log.WriteLine(checkBoxes.Count().ToString());
Regards,
Ivaylo
Telerik