This is a migrated thread and some comments may be shown as answers.
DataBind - click event issue
4 Answers 58 Views
This is a migrated thread and some comments may be shown as answers.
Santosh
Top achievements
Rank 1
Santosh asked on 21 Mar 2012, 02:18 PM
Hi,
I am trying to figure out a way in which i can use data driven from an excel sheet to repeat a sequence of steps.
Attached is the html view and below code which i am using. The RED tick in the attachment is the text (Product -Gain/Loss) which i would like to enter and pick from an excel sheet. Similarly for each repeat sequence different text will be picked up from an excel sheet.

The below code helps me get the correct text value and perform a click event some times and sometimes it gives an error . But even if it works for the first iteration it gives an error when it moves to the second iteration to pick the second text value from the excel sheet.


HtmlDiv e = Find.ByExpression<HtmlDiv>("id=ReadyToUse_Reports");
string SelectedReport = Convert.ToString(Data["B"].ToString()).Trim();
HtmlAnchor a = e.Find.ByContent<HtmlAnchor>(SelectedReport, FindContentType.InnerText);
              or
HtmlAnchor a= e.Find.ByContent<HtmlAnchor>(SelectedReport, FindContentType.TextContent);
Assert.IsNotNull(a);
a.Click();


Can you guys help me on this please?
Thanks,
Santosh

4 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 21 Mar 2012, 06:53 PM
Hello Santosh,

First, I wonder why you've established an HtmlAnchor, as the "Product Gains/Loss" is not a link, it's contained in a <label> element. Try the following instead:

Element first = e.Find.ByExpression("tagname=label", "innertext=" + SelectedReport);
Assert.IsNotNull(first);
Actions.Click(first);

That approach is currently necessary because there's a bug when searching for a parent HTML Control by InnerText. You can find the PITS Issue here: Public URL.  


Kind regards,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Santosh
Top achievements
Rank 1
answered on 26 Mar 2012, 11:59 AM
Hi Anthony, 
The code provided by you does not work. 
To let you know what i am trying to achieve, i have recored the step and provided the code.

When i record the step, and view step in code.. below is the auto generated code which i get. 
        [CodedStep(@"Verify 'InnerText' 'Exact' 'Product Gains/Loss' on 'ProductLink'")]
       public void WebTest1_CodedStep3()
       {
           // Verify 'InnerText' 'Exact' 'Product Gains/Loss' on 'ProductLink'
           Pages.WPOUATV1123WS020.ProductLink.AssertContent().InnerText(ArtOfTest.Common.StringCompareType.Exact, "Product Gains/Loss");
       }

       [CodedStep(@"Click 'ProductLink'")]
        public void WebTest1_CodedStep2()
        {
            // Click 'ProductLink'
            Pages.WPOUATV1123WS020.ProductLink.Click(false);
        }


Note: The label inner text "Product Gains/Loss" which i want to pick, on recording is taken as a (ProductLink) link.
I would like to get "ProductLink" or "Product Gains/Loss" from an external excel sheet and data bind.
the below code is generated in the pages.cs file.
       public ArtOfTest.WebAii.Controls.HtmlControls.HtmlAnchor ProductLink
           {
               get
               {
                   return Get<ArtOfTest.WebAii.Controls.HtmlControls.HtmlAnchor>("TextContent=^Product Gains/L", "tagname=a");
               }
           }
Please consider the previous mail (html view) attachment aswell and help me how to achieve it.
Regards,
Santosh
0
Anthony
Telerik team
answered on 26 Mar 2012, 06:34 PM
Hello Santosh,

Thanks for the additional information. Try the following code instead:

HtmlDiv e = Find.ById<HtmlDiv>("ReadyToUse_Reports");
string SelectedReport = Data["B"].ToString().Trim();
 
HtmlAnchor a = e.Find.ByContent<HtmlAnchor>(SelectedReport);
a.Click();

In the Pages file in your example, the ProductLink is identified by TextContent and not InnerText. If you still wish to use InnerText, use this approach:

HtmlDiv e = Find.ById<HtmlDiv>("ReadyToUse_Reports");
string SelectedReport = Data["B"].ToString().Trim();
 
HtmlAnchor a = e.Find.ByExpression<HtmlAnchor>("tagname=a", "innertext=" + SelectedReport);
a.Click();


Greetings,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Ohsha
Top achievements
Rank 1
answered on 27 Mar 2012, 03:18 PM
Santosh,I didn't see any HtmlAnchor in your attached picture, around the RED tick. 
Can you clarify on that please? 

Thanks

Asked by
Santosh
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Santosh
Top achievements
Rank 1
Ohsha
Top achievements
Rank 1
Share this question
or