This is a migrated thread and some comments may be shown as answers.

HTML Validation of Buttons and Expiration dates

7 Answers 91 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 2
John asked on 08 Aug 2012, 02:33 PM

I’m trying to do a few things in the Grid that Telerik Automation can’t do in Code.  We have a products list that contains a button with the product name and the expiration date in the HTML Grid.

Part one is to gather the button’s names with the Expiration Date.  Then we will do the account updates then run another test that will validate no changes are done.  I need this to be data driven. The issue is that I encounter errors. 

 

Exception thrown executing coded step: '[Row_Index] : @"Indxing through Active'.

InnerException:

System.NullReferenceException: Object reference not set to an instance of an object.

   at PortalC_Sharp.ExpDate_Extract.Row_Index() in C:\MyProjects\PortalC_Sharp\ExpDates\ExpDate Extract.tstest.cs:line 119

------------------------------------------------------------

'8/8/2012 9:23:57 AM' - Detected a failure. Step is marked 'ContinueOnFailure=False' aborting test execution.

 

Can you look at my code to see what I’m doing wrong?

Thanks,

John



<TBODY>
<TR>
<TD style="WIDTH: 100%">
<TABLE width="100%" align=left>
<TBODY>
<TR vAlign=top>
<TD style="WIDTH: 100%; COLOR: navy; FONT-WEIGHT: bold" align=left><A style="WIDTH: 135px; DISPLAY: inline-block" id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl02_rbProduct class="RadButton RadButton_Windows7 rbSkinnedButton" href="javascript:void(0)"><INPUT style="PADDING-LEFT: 4px; WIDTH: 100%; PADDING-RIGHT: 0px" id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl02_rbProduct_input class=rbDecorated tabIndex=-1 value=E-dition type=submit name=ctl00$cphApp$rdProducts$C$grdMyProducts$ctl02$rbProduct_input><INPUT id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl02_rbProduct_ClientState type=hidden name=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl02_rbProduct_ClientState autocomplete="off"></A> </TD>
<TD style="WIDTH: 100%" noWrap align=right><IMG id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl02_imgAttention src="Images/error.png"
<DIV style="POSITION: absolute; DISPLAY: none" id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl02_rtAttention><INPUT id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl02_rtAttention_ClientState type=hidden name=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl02_rtAttention_ClientState autocomplete="off"> </DIV></TD>
<TD noWrap align=right><SPAN style="COLOR: darkgreen" id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl02_lblExpiration>Expiration: Jan 01, 2013</SPAN> </TD></TR>
<TR vAlign=top>
<TD colSpan=3 align=left><INPUT id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl02_lblMessage value="Now current standards are just a few clicks away with E-dition, delivering 24/7 web-based access to all content in the printed <i>Joint Commission Comprehensive Accreditation Manual</i>. Quick-click navigation and automatic updates provide you with the essential standards information you and your staff need. Full-text searching delivers rapid access to topics and you can use filtering and service profilesto tailor views to your needs. Plus, quickly understand how Joint Commission elements of performance relate to CMS requirements through our interactive crosswalk. " type=hidden name=ctl00$cphApp$rdProducts$C$grdMyProducts$ctl02$lblMessage> <SPAN id=message>Now current standards are just a few clicks away with E-dition, delivering 24/7 web-based access to all </SPAN> <IMG style="FLOAT: right; CLEAR: right" id=imgToggleMessage src="http://sandweb2k8.jcaho.net:42111/Images/Icons/iconShowMore.gif" jQuery1703061065552459071="1"></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD style="WIDTH: 100%">
<TABLE width="100%" align=left>
<TBODY>
<TR vAlign=top>
<TD style="WIDTH: 100%; COLOR: navy; FONT-WEIGHT: bold" align=left><A style="WIDTH: 135px; DISPLAY: inline-block" id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl03_rbProduct class="RadButton RadButton_Windows7 rbSkinnedButton" href="javascript:void(0)"><INPUT style="PADDING-LEFT: 4px; WIDTH: 100%; PADDING-RIGHT: 0px" id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl03_rbProduct_input class=rbDecorated tabIndex=-1 value=AMP type=submit name=ctl00$cphApp$rdProducts$C$grdMyProducts$ctl03$rbProduct_input><INPUT id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl03_rbProduct_ClientState type=hidden name=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl03_rbProduct_ClientState autocomplete="off"></A> </TD>
<TD style="WIDTH: 100%" noWrap align=right><IMG id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl03_imgAttention src="Images/4CR.png"
<DIV style="POSITION: absolute; DISPLAY: none" id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl03_rtAttention><INPUT id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl03_rtAttention_ClientState type=hidden name=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl03_rtAttention_ClientState autocomplete="off"> </DIV></TD>
<TD noWrap align=right><SPAN style="COLOR: darkgreen" id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl03_lblExpiration>Expiration: Jan 01, 2013</SPAN> </TD></TR>
<TR vAlign=top>
<TD colSpan=3 align=left><INPUT id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl03_lblMessage value="Accreditation Manager Plus (AMP®) is the software solution for managing your continuous compliance preparation process. AMP simplifies self-assessment across your organization and provides a central location for all accreditation activities.  When it comes time to completing your organization's PPR, simply export your AMP scoring data directly to The Joint Commission site." type=hidden name=ctl00$cphApp$rdProducts$C$grdMyProducts$ctl03$lblMessage> <SPAN id=message>Accreditation Manager Plus (AMP®) is the software solution for managing your continuous compliance prepa</SPAN> <IMG style="FLOAT: right; CLEAR: right" id=imgToggleMessage src="http://sandweb2k8.jcaho.net:42111/Images/Icons/iconShowMore.gif" jQuery1703061065552459071="2"></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD style="WIDTH: 100%">
<TABLE width="100%" align=left>
<TBODY>
<TR vAlign=top>
<TD style="WIDTH: 100%; COLOR: navy; FONT-WEIGHT: bold" align=left><A style="WIDTH: 135px; DISPLAY: inline-block" id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl04_rbProduct class="RadButton RadButton_Windows7 rbSkinnedButton rbDisabled" disabled href="javascript:void(0)"><INPUT style="PADDING-LEFT: 4px; WIDTH: 100%; PADDING-RIGHT: 0px" id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl04_rbProduct_input class=rbDecorated disabled tabIndex=-1 value=ECM type=submit name=ctl00$cphApp$rdProducts$C$grdMyProducts$ctl04$rbProduct_input><INPUT id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl04_rbProduct_ClientState type=hidden name=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl04_rbProduct_ClientState autocomplete="off"></A> </TD>
<TD style="WIDTH: 100%" noWrap align=right><IMG id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl04_imgAttention src="Images/error.png"
<DIV style="POSITION: absolute; DISPLAY: none" id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl04_rtAttention><INPUT id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl04_rtAttention_ClientState type=hidden name=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl04_rtAttention_ClientState autocomplete="off"> </DIV></TD>
<TD noWrap align=right><SPAN style="COLOR: maroon" id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl04_lblExpiration>Expiration: Mar 02, 2012</SPAN> </TD></TR>
<TR vAlign=top>
<TD colSpan=3 align=left><INPUT id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl04_lblMessage value="E-dition Compliance Monitor (ECM™) is an online library of health care industry regulations, organized and linked by Joint Commission Hospital Standards, designed to help you navigate the laws, regulations, and daily actions made by various government and regulatory agencies.<br/><br/>By having a central repository for standards and regulatory information, ECM gives you the tools you need to help reduce risk, avoid costly compliance deficiencies, and ultimately improve patient safety.<br/><br/>Updated daily, ECM features the easy-to-use E-dition® interface and navigation, and provides expanded search and filter features for quick retrieval of information.  This software also features a “What’s New” e-mail alert tailored to your specific areas of interest." type=hidden name=ctl00$cphApp$rdProducts$C$grdMyProducts$ctl04$lblMessage> <SPAN id=message>E-dition Compliance Monitor (ECM™) is an online library of health care industry regulations, organized a</SPAN> <IMG style="FLOAT: right; CLEAR: right" id=imgToggleMessage src="http://sandweb2k8.jcaho.net:42111/Images/Icons/iconShowMore.gif" jQuery1703061065552459071="3"></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD style="WIDTH: 100%">
<TABLE width="100%" align=left>
<TBODY>
<TR vAlign=top>
<TD style="WIDTH: 100%; COLOR: navy; FONT-WEIGHT: bold" align=left><A style="WIDTH: 135px; DISPLAY: inline-block" id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl05_rbProduct class="RadButton RadButton_Windows7 rbSkinnedButton" href="javascript:void(0)"><INPUT style="PADDING-LEFT: 4px; WIDTH: 100%; PADDING-RIGHT: 0px" id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl05_rbProduct_input class=rbDecorated tabIndex=-1 value=Tracers type=submit name=ctl00$cphApp$rdProducts$C$grdMyProducts$ctl05$rbProduct_input><INPUT id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl05_rbProduct_ClientState type=hidden name=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl05_rbProduct_ClientState autocomplete="off"></A> </TD>
<TD style="WIDTH: 100%" noWrap align=right><IMG id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl05_imgAttention src="Images/4CR.png"
<DIV style="POSITION: absolute; DISPLAY: none" id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl05_rtAttention><INPUT id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl05_rtAttention_ClientState type=hidden name=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl05_rtAttention_ClientState autocomplete="off"> </DIV></TD>
<TD noWrap align=right><SPAN style="COLOR: darkgreen" id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl05_lblExpiration>Expiration: Jan 01, 2013</SPAN> </TD></TR>
<TR vAlign=top>
<TD colSpan=3 align=left><INPUT id=ctl00_cphApp_rdProducts_C_grdMyProducts_ctl05_lblMessage value="An online tool that allows users to record, track and trend internal Tracer activities by creating a custom tracer from existing Joint Commission Resources templates of questions  or from questions customized or created by your organization." type=hidden name=ctl00$cphApp$rdProducts$C$grdMyProducts$ctl05$lblMessage> <SPAN id=message>An online tool that allows users to record, track and trend internal Tracer activities by creating a cus</SPAN> <IMG style="FLOAT: right; CLEAR: right" id=imgToggleMessage src="http://sandweb2k8.jcaho.net:42111/Images/Icons/iconShowMore.gif" jQuery1703061065552459071="4"></TD></TR></TBODY></TABLE></TD></TR></TBODY>


Here is my code:

[

 

CodedStep(@"Indxing through Active")]

 

 

 

public void Row_Index()

 

{

 

 

    HtmlTable ContenthtmlTable = Pages.JointCommissionResources6.MyActive.Find.ById<HtmlTable>("ctl00_cphApp_rdProducts_C");

 

 

 

 

    HtmlDiv gridDiv = Find.ById<HtmlDiv>("ctl00_cphApp_rdProducts_C");

 

 

 

    HtmlDiv content = gridDiv.Find.ByAttributes<HtmlDiv>("id=ctl00_cphApp_rdProducts_C_grdMyProducts");

 

 

 

 

    HtmlTable table = content.Find.ByTagIndex<HtmlTable>("table", 0);

 

    Log.WriteLine(

 

"***********************************************");

 

    Log.WriteLine(

 

"Rows Count: " + table.Rows.Count.ToString());

 

    Log.WriteLine(

 

"***********************************************");

 

 

 

 

 

    foreach (HtmlTableRow row in table.AllRows)

 

    {

 

 

       foreach (HtmlTableCell cell in row.Cells)

 

       {

           Log.WriteLine(cell.InnerText);

       }

     }

 

}



7 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 13 Aug 2012, 10:05 AM
Hello John,

Looking the provided HTML, I'm not able to find the HtmlTable element with id="ctl00_cphApp_rdProducts_C".

Furthermore, there are no HtmlDiv elements defined with the following IDs:
    "ctl00_cphApp_rdProducts_C"
    "ctl00_cphApp_rdProducts_C_grdMyProducts"

In result, when I'm running your code I'm getting the exact same exception, because the elements above does not exist. If I add a parent HtmlTable element in the HTML with id: "ctl00_cphApp_rdProducts_C" and remove the lines where you are searching for the non existing HtmlDiv elements, the test runs as expected. See this video.

In order to help you further with your scenario, please provide the complete HTML containing the missing elements.

Regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
John
Top achievements
Rank 2
answered on 13 Aug 2012, 12:21 PM
Plamen,
Here is the HTML page.

thanks,
John
0
Plamen
Telerik team
answered on 14 Aug 2012, 03:27 PM
Hi John,

Thank you for providing the complete HTML code.

In order to get the text of the button you need to find it as an HtmlInputControl and use its Value property. Here's a sample code:
HtmlTable table = ActiveBrowser.Find.ByAttributes<HtmlTable>("id=ctl00_cphApp_rdProducts_C_grdMyProducts");
 
Log.WriteLine("***********************************************");
Log.WriteLine("Rows Count: " + table.Rows.Count.ToString());
Log.WriteLine("***********************************************");
 
foreach (HtmlTableRow row in table.AllRows)
{
    HtmlInputControl btn = row.Find.ByAttributes<HtmlInputControl>("class=rbDecorated");
    Log.WriteLine(btn.Value + " - " + row.InnerText);
}

Please see this short video demonstrating the execution and let me know if you need further assistance on this.

Regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
John
Top achievements
Rank 2
answered on 15 Aug 2012, 12:52 PM
I'm seeing the following error: 

Error 2
The type 'PortalC_Sharp.HtmlTable' cannot be used as type parameter 'TControl' in the generic type or method 'ArtOfTest.WebAii.Core.Find.ByAttributes<TControl>(params string[])'. There is no implicit reference conversion from 'PortalC_Sharp.HtmlTable' to 'ArtOfTest.WebAii.Controls.Control'.
C:\MyProjects\PortalC_Sharp\Sample Code\ExpDateCode.tstest.cs 76 31 PortalC_Sharp

public class ExpDateCode : BaseWebAiiTest
    {
        #region [ Dynamic Pages Reference ]
 
        private Pages _pages;
 
        /// <summary>
        /// Gets the Pages object that has references
        /// to all the elements, frames or regions
        /// in this project.
        /// </summary>
        public Pages Pages
        {
            get
            {
                if (_pages == null)
                {
                    _pages = new Pages(Manager.Current);
                }
                return _pages;
            }
        }
 
        #endregion
 
        [CodedStep(@"Exp Date Test")]
        public void ExpDateCode_CodedStep()
        {
            HtmlTable table = ActiveBrowser.Find.ByAttributes<HtmlTable>("id=ctl00_cphApp_rdProducts_C_grdMyProducts");
 
            Log.WriteLine("************************************************************************");
            Log.WriteLine("Rows Count: " + table.Rows.Count.ToString());
            Log.WriteLine("************************************************************************");
 
            foreach (HtmlTableRow row in table.AllRows)
            {
 
                HtmlInputControl btn = row.Find.ByAttributes<HtmlInputControl>("class=rbDrcorated");
                Log.WriteLine(btn.Value + " - " + row.InnerText);
 
            }
 
        }
0
Plamen
Telerik team
answered on 15 Aug 2012, 03:41 PM
Hello John,

According to the error message, you already have an HtmlTable class defined somewhere in the "PortalC_Sharp" namespace. In order to overcome this, you can either remove the existing class or use the full path to our HtmlTable class in the ArtOfTest.WebAii.Controls.HtmlControls namespace.

Here's the code you can use if you choose the second option:
ArtOfTest.WebAii.Controls.HtmlControls.HtmlTable table = ActiveBrowser.Find.ByAttributes<ArtOfTest.WebAii.Controls.HtmlControls.HtmlTable>("id=ctl00_cphApp_rdProducts_C_grdMyProducts");
 
Log.WriteLine("***********************************************");
Log.WriteLine("Rows Count: " + table.Rows.Count.ToString());
Log.WriteLine("***********************************************");
 
foreach (ArtOfTest.WebAii.Controls.HtmlControls.HtmlTableRow row in table.AllRows)
{
    ArtOfTest.WebAii.Controls.HtmlControls.HtmlInputControl btn = row.Find.ByAttributes<ArtOfTest.WebAii.Controls.HtmlControls.HtmlInputControl>("class=rbDecorated");
    Log.WriteLine(btn.Value + " - " + row.InnerText);
}


Kind regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
John
Top achievements
Rank 2
answered on 17 Aug 2012, 10:44 PM
Hi,
I'm looking at the code and I'm changing the code to grab the expiration date. I was wondering how I can get the date assigned to a String? 

thanks,
John
0
Plamen
Telerik team
answered on 20 Aug 2012, 11:53 AM
Hello John,

You can use the String.Substring method.

For example, if you have the following string:
string expiration = "Expiration: Jan 01, 2013";

You can get only the date with code like this:
string expirationDate = (expiration.Substring(12));

All the best,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
John
Top achievements
Rank 2
Answers by
Plamen
Telerik team
John
Top achievements
Rank 2
Share this question
or