Hi Team
I need to select the check boxes and radio buttons in my screen. Please refer the below code snippet.It works fine and I am selecting the checkboxes 1 after the other and also I am hardcoding in to less then or equal to 3
Code snippet 1:
******************
DivTag DTtag = webdoc.FindSingle("/dom[@domain>'cvgu' and @browser~'.*Guidewire.*']//div[@id~'.*QuestionSetLV-body']");
for(int i=1;i<=3;i++)
{
ImgTag img = DTtag.FindSingle("/dom[@domain>'cvgu' and @browser~'.*Guidewire.*']//tr[@id~'gridview*']//img[@src~'data:image*' and @class='x-grid-checkcolumn' and @tagname='img']");
img.Click();
}
Here, I have 2 questions.
1) I have tried the same by using "FindChildrens", however i not successful. It's always gives the count as 0. Attached code snippet 2 for your reference.
2) Is there any way to select all the checkboxes at 1 shot?
Please advise
Code snippet 2:
*****************
DivTag DTtag = webdoc.FindSingle("/dom[@domain>'cvgu' and @browser~'.*Guidewire.*']//div[@id~'.*QuestionSetLV-body']");
ImgTag img = DTtag.FindSingle("/dom[@domain>'cvgu' and @browser~'.*Guidewire.*']//tr[@id~'gridview*']//img[@src~'data:image*' and @class='x-grid-checkcolumn' and @tagname='img']");
IList<ImgTag> ImgChild = img.FindChildren<ImgTag>("/dom[@domain>'cvgu' and @browser~'.*Guidewire.*']//tr[@id~'gridview*']//img[@src~'data:image*' and @class='x-grid-checkcolumn' and @tagname='img']");
foreach (ImgTag obj in ImgChild)
{
obj.Click();
}
Dynamic coding using C# - Find children
Dynamic coding using C# - Find children
You do not have the required permissions to view the files attached to this post.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Dynamic coding using C# - Find children
Attention, the FindChildren(string defaultLabel) does not take a RanoreXPath as argument, but a label. As this already caused confusion, the method is marked as obsolete (you get a warning if using it) and will be deleted in a future version of Ranorex.vivek wrote:I have tried the same by using "FindChildrens", however i not successful
IMHO what you are searching for is the Find(RxPath) method which returns you all elements satisfying the passed RanoreXPath.
Just use the Find instead of the FindChildren method to retrieve all ImgTag elements and loop through the returned elements.vivek wrote:Is there any way to select all the checkboxes at 1 shot?
Regards,
Alex
Ranorex Team
Re: Dynamic coding using C# - Find children
Hi Alex
Thanks for your help. I have coded using "Find" and it works.
Please refer the code snippet. It works this way. Here I am finding my object once again inside the loop and click it
Code snippet Worked
ImgTag img = webdoc.FindSingle("/dom[@domain>'cvgu' and @browser~'.*Guidewire.*']//tr[@id~'gridview*']//img[@src~'image*' and @class='x-grid-checkcolumn' and @tagname~'img']");
IList<ImgTag> ImgChild = img.Find<ImgTag>("/dom[@domain>'cvgu' and @browser~'.*Guidewire.*']//tr[@id~'gridview*']//img[@src~'image*' and @class='x-grid-checkcolumn' and @tagname~'img']"
foreach (ImgTag obj in ImgChild)
{
ImgTag imgclk = webdoc.FindSingle("/dom[@domain>'cvgu' and @browser~'.*Guidewire.*']//tr[@id~'gridview*']//img[@src~'image*' and @class='x-grid-checkcolumn' and @tagname~'img']");
imgclk.Click();
}
On the flip side, See below. I am referencing the for each loop object and clicked it. I am not successful here, It find the first image object but it't not able to find the other object.
I am getting error message as "Could not get a valid element rectangle image". I have checked in spy and it can able to recognize all the images.
Any help will be appreciated
Code snippet - having issues
********************************
ImgTag img = webdoc.FindSingle("/dom[@domain>'cvgu' and @browser~'.*Guidewire.*']//tr[@id~'gridview*']//img[@src~'image*' and @class='x-grid-checkcolumn' and @tagname~'img']");
IList<ImgTag> ImgChild = img.Find<ImgTag>("/dom[@domain>'cvgu' and @browser~'.*Guidewire.*']//tr[@id~'gridview*']//img[@src~'image*' and @class='x-grid-checkcolumn' and @tagname~'img']"
foreach (ImgTag obj in ImgChild)
{
obj.Click();
}
Thanks for your help. I have coded using "Find" and it works.
Please refer the code snippet. It works this way. Here I am finding my object once again inside the loop and click it
Code snippet Worked
ImgTag img = webdoc.FindSingle("/dom[@domain>'cvgu' and @browser~'.*Guidewire.*']//tr[@id~'gridview*']//img[@src~'image*' and @class='x-grid-checkcolumn' and @tagname~'img']");
IList<ImgTag> ImgChild = img.Find<ImgTag>("/dom[@domain>'cvgu' and @browser~'.*Guidewire.*']//tr[@id~'gridview*']//img[@src~'image*' and @class='x-grid-checkcolumn' and @tagname~'img']"
foreach (ImgTag obj in ImgChild)
{
ImgTag imgclk = webdoc.FindSingle("/dom[@domain>'cvgu' and @browser~'.*Guidewire.*']//tr[@id~'gridview*']//img[@src~'image*' and @class='x-grid-checkcolumn' and @tagname~'img']");
imgclk.Click();
}
On the flip side, See below. I am referencing the for each loop object and clicked it. I am not successful here, It find the first image object but it't not able to find the other object.
I am getting error message as "Could not get a valid element rectangle image". I have checked in spy and it can able to recognize all the images.
Any help will be appreciated
Code snippet - having issues
********************************
ImgTag img = webdoc.FindSingle("/dom[@domain>'cvgu' and @browser~'.*Guidewire.*']//tr[@id~'gridview*']//img[@src~'image*' and @class='x-grid-checkcolumn' and @tagname~'img']");
IList<ImgTag> ImgChild = img.Find<ImgTag>("/dom[@domain>'cvgu' and @browser~'.*Guidewire.*']//tr[@id~'gridview*']//img[@src~'image*' and @class='x-grid-checkcolumn' and @tagname~'img']"
foreach (ImgTag obj in ImgChild)
{
obj.Click();
}
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Dynamic coding using C# - Find children
Hi vivek,
It is most probably a problem with caching. You are searching for all img elements and save this elements in your list, and it seems that your web page is reloaded during the click actions Ranorex performs. This is why Ranorex can no longer get a valid rectangle, since the img element saved does no longer exist, a new one was created instead.
May I ask you to post a Ranorex snapshot file of your img elements here? This will help me to to help you writing a suitable method.
The following link will show you how to generate a snapshot file: Creating Ranorex Snapshot Files.
Why Ranorex always clicks on the first element in the first method is because you are always searching for the same element, with the same RxPath. When there are more elements with the same RxPath Ranorex will just return the first one.
Regards,
Markus
It is most probably a problem with caching. You are searching for all img elements and save this elements in your list, and it seems that your web page is reloaded during the click actions Ranorex performs. This is why Ranorex can no longer get a valid rectangle, since the img element saved does no longer exist, a new one was created instead.
May I ask you to post a Ranorex snapshot file of your img elements here? This will help me to to help you writing a suitable method.
The following link will show you how to generate a snapshot file: Creating Ranorex Snapshot Files.
Why Ranorex always clicks on the first element in the first method is because you are always searching for the same element, with the same RxPath. When there are more elements with the same RxPath Ranorex will just return the first one.
Regards,
Markus