Find.ById() couldn't find control & throw an exception

3 posts, 0 answers
  1. Behtash Moradi
    Behtash Moradi avatar
    9 posts
    Member since:
    Nov 2009

    Posted 17 Mar 2011 Link to this post

    I have a .aspx page with 4 panels which works a wizard, I mean that in each step, only one panel is visible in browser.
    I developed an UI  test using Telerik framework, it could only find  the control in first step, and when the  second panel is shown 
    ,test methods failed to find controls and throw exception. see below code which is simplified version of my page

                
    ActiveBrowser.NavigateTo("http://localhost:34126/");<br>                    <br>            Thread.Sleep(1000);<br><br><span class="Apple-tab-span" style="white-space:pre">    </span>// step  #1 , a panel with only one drop down list & next button<br>            Find.ById<HtmlSelect>("cmbxList").SelectByIndex(1);  // successfully find drop down list and set selected item,<br>            Find.ById<HtmlButton>("lnkNext").Click(); // goes to step #2 <br><br><span class="Apple-tab-span" style="white-space:pre">   </span>// step #2 a panel with some input controld<br>             Find.ById<HtmlInputControl>("txtEmailTitle").Value = "behtash"; // failed<br>             Find.ById<HtmlInputControl>("txtReplyAddress").Value = "info@ctx.com";


     panel are placed in a update panel

    structure of page is something like this:

    <asp:updatepanel>
    <contentTemplate>
    <asp:Panle Id="panel1></asp:Panel> //step 1
    <asp:Panle Id="panel2></asp:Panel> //step 2
    <asp:Panle Id="panel3></asp:Panel>//step 3
    <asp:Panle Id="panel4></asp:Panel> //step 4
    <contentTemplate>
    </asp:updatepanel>



    Thnaks
    Behtash Moradi

  2. Behtash Moradi
    Behtash Moradi avatar
    9 posts
    Member since:
    Nov 2009

    Posted 17 Mar 2011 Link to this post

    I added  the test method code again

    testmethod()
    {
    ActiveBrowser.NavigateTo("http://localhost:34126/")
    Thread.Sleep(1000);

    // step  #1 , a panel with only one drop down list & next button
    Find.ById<HtmlSelect>("cmbxList").SelectByIndex(1);//successfully find drop down list and set
    Find.ById<
    HtmlButton>("lnkNext").Click(); // goes to step #2

    // step #2 a panel with some input controld
    Find.ById<HtmlInputControl>("txtEmailTitle").Value = "behtash"; // failed
    to find control on page

    }
     As I checked, when I record   test scenario using Telerik recorder and replay it, it works fine  since it creates a class  per client side page which contains wrapper properties  for page controls ,  and getter of these properties, it is using HtmlElmenetContainer.Get  method for finding controls. how I should HtmlElmenetContainer.Get in my test and what is difference between Get and Find ?

      I would like to develop test manually instead of using code which is generated by telerik test recorders. i successfully manged to develop test for some scenarios but it failed in this case.

    Please advise
    Thanks
    Behtash

  3. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 23 Mar 2011 Link to this post

    Hello Behtash,
       it's hard to say why your code is failing without look at your application. Any number of things might have gone wrong.
    You state this line of code is the problem:
    Find.ById<HtmlInputControl>("txtEmailTitle").Value = "behtash";
    What kind of error does it throw?
    Are you sure the ID for the element is correct and unique?
    Are  you sure you're looking in the correct page?

    Also, it's always a good idea
    to wait for element to appear. Check out his video:
    http://www.telerik.com/automated-testing-tools/support/videos/best-practices/recording-best-practices.aspx

    Consider using Test Studio - it's designed to save time and make Automation task much easier.

    Hope to hear from you soon!

    Greetings,
    Stoich
    the Telerik team
Back to Top