<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Relevant Codes (by Anshoo Arora) &#187; QTP/Web</title>
	<atom:link href="http://relevantcodes.com/category/qtpweb/feed/" rel="self" type="application/rss+xml" />
	<link>http://relevantcodes.com</link>
	<description>A Resource for Test Automation Development</description>
	<lastBuildDate>Thu, 10 May 2012 10:32:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Get Row/Column Of An Object in a WebTable</title>
		<link>http://relevantcodes.com/get-rowcolumn-of-an-object-in-a-webtable/</link>
		<comments>http://relevantcodes.com/get-rowcolumn-of-an-object-in-a-webtable/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 05:03:28 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/Web]]></category>
		<category><![CDATA[cellIndex]]></category>
		<category><![CDATA[CellInfo]]></category>
		<category><![CDATA[Column]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[Object inside Table]]></category>
		<category><![CDATA[QTP Object inside WebTable]]></category>
		<category><![CDATA[Row]]></category>
		<category><![CDATA[rowIndex]]></category>
		<category><![CDATA[td]]></category>
		<category><![CDATA[tr]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=4218</guid>
		<description><![CDATA[This article shows a simple way of finding out in which cell a QTP's Test Object resides.]]></description>
			<content:encoded><![CDATA[<p></p><p>
This article shows a simple way of finding out in which cell a QTP&#8217;s Test Object resides. I find the method shown in this article a more effective and faster way of finding the cell I&#8217;m looking for. I have found that this method performs better than traversing rows/cells of a WebTable using in-built WebTable methods such as ChildItem, ChildItemCount and GetCellData. Also, for test objects, it is also not possible to find an exact match with the methods provided for WebTable &#8211; it is only possible for strings.
</p>
<p>
A workaround to find objects inside WebTable using DOM table/tr/td is shown in this article. The code snippets below show how to retrieve the row and column of a given object from a WebTable.
</p>
<p>
Consider the element &#8220;Doe&#8221; in the table below. We can visually see that the link is in the 5th row (starting at the heading) and the 3rd column.
</p>
<table style='margin-left:auto; margin-right:auto;background: #fff;border-collapse: collapse;text-align: left;margin-bottom:27px;'>
<tr>
<th style='color: #039;padding: 10px 8px;border: 1px solid #ccc;'>ID</td>
<th style='color: #039;padding: 10px 8px;border: 1px solid #ccc;'>First Name</td>
<th style='color: #039;padding: 10px 8px;border: 1px solid #ccc;'>Last Name</td>
<th style='color: #039;padding: 10px 8px;border: 1px solid #ccc;'>Gender</td>
<th style='color: #039;padding: 10px 8px;border: 1px solid #ccc;'>Attending class?</td>
</tr>
<tr>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>12345</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>John</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Smith</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>M</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>
<input type='checkbox' name='attending'></td>
</tr>
<tr>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>12346</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Anne</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Johnson</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>F</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>
<input type='checkbox' name='attending'></td>
</tr>
<tr>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>12347</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Adam</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Roberts</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>M</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>
<input type='checkbox' name='attending'></td>
</tr>
<tr>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>12348</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Mary</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Doe</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>F</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>
<input type='checkbox' name='attending'></td>
</tr>
<tr>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>12349</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Tiffany</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>Smith</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>F</td>
<td style='border: 1px solid #ccc;color: #669;padding: 6px 8px;'>
<input type='checkbox' name='attending'></td>
</tr>
</table>
<p>
Executing the following code will provide us our expected output:
</p>
<pre>
Set element = Browser("creationtime:=0").WebElement("innertext:=Doe", "index:=0")

MsgBox "Row# " &#038; element.GetRow()
MsgBox "Col# " &#038; element.GetColumn()
</pre>
<table style='margin-left: auto; margin-right: auto;'>
<tr>
<td><img alt="" src="http://relevantcodes.com/Articles/FindTableCellFromObject/row.png" title="Row Output" class="alignnone" width="154" height="154" /></td>
<td><img alt="" src="http://relevantcodes.com/Articles/FindTableCellFromObject/column.png" title="Column Output" class="alignnone" width="154" height="154" /></td>
</tr>
</table>
<p>
The above example uses WebElement, but <strong>this approach works for all Web objects.</strong> Similarly, the code for finding the 2nd WebCheckBox for Anne Johnson will give us:  <code>Row# 3</code> and <code>Column#5</code> with the following code:
</p>
<pre>
MsgBox Browser("creationtime:=0").WebCheckBox("name:=attending", "index:=1").GetRow
MsgBox Browser("creationtime:=0").WebCheckBox("name:=attending", "index:=1").GetColumn
</pre>
<h2>The Code</h2>
<p>
The following two methods can be used directly for the object and will retrieve &#8216;either&#8217; the row or the column. The below method retrieves the Row for an object residing in a WebTable:
</p>
<h5>Find Row of the Object from WebTable</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> GetRow(<span style="color: #0600FF; font-weight: bold;">ByVal</span> TObject)
    GetRow = -1
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Set</span> TObject = TObject.<span style="color: #6666CC; font-weight: bold;">Object</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Do</span>
        <span style="color: #0600FF; font-weight: bold;">If</span> TObject.nodeName = <span style="color: #800000;">&quot;TR&quot;</span> <span style="color: #0600FF; font-weight: bold;">Then</span>
            GetRow = TObject.rowIndex + 1
            <span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Set</span> TObject = TObject.parentNode
    <span style="color: #0600FF; font-weight: bold;">Loop</span> <span style="color: #0600FF; font-weight: bold;">Until</span> TObject.nodeName = <span style="color: #800000;">&quot;HTML&quot;</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
RegisterUserFunc <span style="color: #800000;">&quot;Image&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;Link&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebEdit&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebList&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebCheckBox&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebElement&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebRadioGroup&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span>, <span style="color: #800000;">&quot;GetRow&quot;</span></pre></div></div>

<h5>Example</h5>
<pre>
MsgBox Browser("title:=myBrowser").Link("innertext:=myLink", "index:=1").GetRow
</pre>
<p>
This method returns the column of the object inside a WebTable:
</p>
<h5>Find Column of the Object from WebTable</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> GetColumn(<span style="color: #0600FF; font-weight: bold;">ByVal</span> TObject)
    GetColumn = -1
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Set</span> TObject = TObject.<span style="color: #6666CC; font-weight: bold;">Object</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Do</span>
        <span style="color: #0600FF; font-weight: bold;">If</span> TObject.nodeName = <span style="color: #800000;">&quot;TD&quot;</span> <span style="color: #0600FF; font-weight: bold;">Then</span>
            GetColumn = TObject.cellIndex + 1
            <span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Set</span> TObject = TObject.parentNode
    <span style="color: #0600FF; font-weight: bold;">Loop</span> <span style="color: #0600FF; font-weight: bold;">Until</span> TObject.nodeName = <span style="color: #800000;">&quot;HTML&quot;</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
RegisterUserFunc <span style="color: #800000;">&quot;Image&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;Link&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebEdit&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebList&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebCheckBox&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebElement&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebRadioGroup&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span>, <span style="color: #800000;">&quot;GetColumn&quot;</span></pre></div></div>

<h5>Example</h5>
<pre>
MsgBox Browser("title:=myBrowser").Link("innertext:=myLink", "index:=1").GetColumn
</pre>
<p>
The below implementation retrieves both row and column as a Scripting.Dictionary.
</p>
<h5>Find Row &#038; Column Info as Scripting.Dictionary</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> CellInfo(<span style="color: #0600FF; font-weight: bold;">ByVal</span> TObject)
    <span style="color: #0600FF; font-weight: bold;">Dim</span> dic
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Set</span> dic = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Scripting.Dictionary&quot;</span>)
    dic.Add <span style="color: #800000;">&quot;row&quot;</span>, -1
    dic.Add <span style="color: #800000;">&quot;col&quot;</span>, -1
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Set</span> TObject = TObject.<span style="color: #6666CC; font-weight: bold;">Object</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Do</span>
        <span style="color: #0600FF; font-weight: bold;">If</span> TObject.nodeName = <span style="color: #800000;">&quot;TD&quot;</span> <span style="color: #0600FF; font-weight: bold;">Then</span> dic(<span style="color: #800000;">&quot;col&quot;</span>) = TObject.cellIndex + 1
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">If</span> TObject.nodeName = <span style="color: #800000;">&quot;TR&quot;</span> <span style="color: #0600FF; font-weight: bold;">Then</span>
            dic(<span style="color: #800000;">&quot;row&quot;</span>) = TObject.rowIndex + 1
            <span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Do</span>
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Set</span> TObject = TObject.parentNode
    <span style="color: #0600FF; font-weight: bold;">Loop</span> <span style="color: #0600FF; font-weight: bold;">Until</span> TObject.nodeName = <span style="color: #800000;">&quot;HTML&quot;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Set</span> CellInfo = dic
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
RegisterUserFunc <span style="color: #800000;">&quot;Image&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;Link&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebEdit&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebList&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebRadioGroup&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebElement&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebCheckBox&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span>, <span style="color: #800000;">&quot;CellInfo&quot;</span></pre></div></div>

<h5>Example</h5>
<pre>
Set cells = Browser("title:=myBrowser").Link("innertext:=myLink", "index:=1").CellInfo()

MsgBox cells("row")
MsgBox cells("col")

cells.RemoveAll
Set cells = Nothing
</pre>
<p>
I hope you find this helpful. As always, thanks for visiting Relevant Codes :)</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/get-rowcolumn-of-an-object-in-a-webtable/feed/</wfw:commentRss>
		<slash:comments>68</slash:comments>
		</item>
		<item>
		<title>IE Error: A script is causing IE to run slowly</title>
		<link>http://relevantcodes.com/ie-error-a-script-is-causing-ie-to-run-slowly/</link>
		<comments>http://relevantcodes.com/ie-error-a-script-is-causing-ie-to-run-slowly/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 03:55:25 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/Web]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[IE Error]]></category>
		<category><![CDATA[MaxScriptStatements]]></category>
		<category><![CDATA[QTP Web]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=3973</guid>
		<description><![CDATA[This tip shows how to disable the Error message: "A script on this page is causing Internet Explorer to run slowly" with using VBScript.]]></description>
			<content:encoded><![CDATA[<p></p><p>
While testing a script on IE8, me and my colleague kept getting the error &#8220;A script on this page is causing Internet Explorer to run slowly&#8221;.  Below is a snapshot of the error:</p>
<p><img alt="" class="imgborder" src="http://relevantcodes.com/Articles/IEScriptRunningSlow/ie_error.JPG" title="IE Error: A script is causing IE to run slowly" class="aligncenter" width="340" height="155" /></p>
<p>After some research, I came across an article on MSDN which already had the solution: <a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;175500">Microsoft KB # 175500</a>. The part we are concerned about is in the section &#8220;Let me fix it myself&#8221;:</p>
<p class="info">
1.Using a Registry Editor such as Regedt32.exe, open this key: <i>HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Styles</i><br />
Note: If the Styles key is not present, create a new key that is called Styles.<br />
2. Create a new DWORD value called &#8220;MaxScriptStatements&#8221; under this key and set the value to the desired number of script statements. If you are unsure of what value you need to set this to, you can set it to a DWORD value of 0xFFFFFFFF to completely avoid the dialog.
</p>
<p>
For the curious ones, the article states that, to encounter the error, the DWord value of <strong>0xFFFFFFFF</strong> must be added.  The value equates to -1, which is what has been used in the function below.
</p>
<h5>Code</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Sub</span> IE_ChangeScriptTimeOut()
	<span style="color: #0600FF; font-weight: bold;">Dim</span> Registry, sKeyPath, sValueName, dwValue, sComputer
	CONST HKEY_CURRENT_USER = &amp;H80000001
&nbsp;
	sKeyPath = <span style="color: #800000;">&quot;Software\Microsoft\Internet Explorer\Styles&quot;</span>
	sValueName = <span style="color: #800000;">&quot;MaxScriptStatements&quot;</span>
	dwValue = -1
	sComputer = <span style="color: #800000;">&quot;.&quot;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Resume</span> <span style="color: #0600FF; font-weight: bold;">Next</span>
		<span style="color: #0600FF; font-weight: bold;">Set</span> Registry = <span style="color: #0600FF; font-weight: bold;">GetObject</span>(<span style="color: #800000;">&quot;winmgmts:{impersonationLevel=impersonate}!\\&quot;</span> &amp;_ 
				sComputer &amp; <span style="color: #800000;">&quot;\root\default:StdRegProv&quot;</span>)
&nbsp;
		Registry.CreateKey HKEY_CURRENT_USER, sKeyPath
		Registry.SetDWORDValue HKEY_CURRENT_USER, sKeyPath, sValueName, CLng(dwValue)
	<span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Goto</span> 0
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">Set</span> Registry = <span style="color: #0600FF; font-weight: bold;">Nothing</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span></pre></div></div>

<p>
Thanks for reading, and thanks for visiting Relevant Codes! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/ie-error-a-script-is-causing-ie-to-run-slowly/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>QTP CreationTime</title>
		<link>http://relevantcodes.com/creationtime/</link>
		<comments>http://relevantcodes.com/creationtime/#comments</comments>
		<pubDate>Fri, 03 Sep 2010 11:34:51 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/Web]]></category>
		<category><![CDATA[Browser]]></category>
		<category><![CDATA[Browser Creationtime]]></category>
		<category><![CDATA[CreationTime]]></category>
		<category><![CDATA[Ordinal Identifier]]></category>
		<category><![CDATA[Ordinal Identifier CreationTime]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=3930</guid>
		<description><![CDATA[This article explains how the Browser's CreationTime ordinal identifier works in QTP with examples.]]></description>
			<content:encoded><![CDATA[<p></p><p>
I&#8217;ve generally seen some confusion around CreationTime. I think between the 3 Ordinal Identifiers, this one may be the easiest to understand and implement. That&#8217;s mostly because CreationTime is used <span class="emphasis_u">only</span> for the Browser object. Below is how CreationTime is applied to browsers:
</p>
<pre>
1st open browser -> CreationTime of -> 0
2nd open browser -> CreationTime of -> 1
3rd open browser -> CreationTime of -> 2
4th open browser -> CreationTime of -> 3
</pre>
<p>
According to QTP help:
</p>
<p class="info">
This value indicates the order in which the browser was opened relative to other open browsers. For example, if QuickTest learns three browsers that are opened at 9:01 pm, 9:03 pm, and 9:05 pm, QuickTest assigns the CreationTime values, as follows: CreationTime = 0 to the 9:01 am browser, CreationTime = 1 to the 9:03 am browser, and CreationTime = 2 to the 9:06 am browser.
</p>
<p>
Really, that&#8217;s it! No tricks here! To test it for proof, you can open 4 browsers (with different websites) and run the following code in QTP:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">For</span> ix = 0 <span style="color: #0600FF; font-weight: bold;">to</span> 3
	<span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;CreationTime-&gt;&quot;</span> &amp; ix &amp; <span style="color: #800000;">&quot;-&gt;&quot;</span> &amp; Browser(<span style="color: #800000;">&quot;creationtime:=&quot;</span> &amp; ix).GetROProperty(<span style="color: #800000;">&quot;title&quot;</span>)
<span style="color: #0600FF; font-weight: bold;">Next</span></pre></div></div>

<p>
On my desktop, I&#8217;ve 4 open IE windows in the following order: Google, Bing, Yahoo, Microsoft. See snapshot below:
</p>
<div class="wp-caption aligncenter" style="width: 675px">
	<a href="http://relevantcodes.com/Articles/CreationTime/Taskbar.png"><img alt="My taskbar" src="http://relevantcodes.com/Articles/CreationTime/Taskbar.png" title="My taskbar" width="675" height="22" /></a>
	<p class="wp-caption-text">My taskbar: Click to view original size</p>
</div>
<p>
After running the above code, this is what I see in my print log:
</p>
<div class="wp-caption aligncenter" style="width: 321px">
	<img alt="Print log" src="http://relevantcodes.com/Articles/CreationTime/Output.png" title="Print log" width="321" height="162" />
	<p class="wp-caption-text">Print log</p>
</div>
<p>
The output shows the order in which the IE windows are placed on the Desktop, which is same as the order in which they were opened.
</p>
<h2>The tricky part</h2>
<p>
The only tricky part in this concept is its applicability when there is only one browser open. With one open browser, regardless of the CreationTime value supplied, QTP will always identify the only open browser. This is because, CreationTime values are generated when there are multiple browsers open &#8211; with a single open browser, this value is generally has no usage. This is at least true for QTP 10.0 and previous versions.
</p>
<p>
As always, thanks for visiting Relevant Codes! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/creationtime/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Browser: Not Required!</title>
		<link>http://relevantcodes.com/browser-not-required/</link>
		<comments>http://relevantcodes.com/browser-not-required/#comments</comments>
		<pubDate>Sun, 02 May 2010 17:23:14 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/Web]]></category>
		<category><![CDATA[Browser]]></category>
		<category><![CDATA[Page]]></category>
		<category><![CDATA[QTP Web]]></category>
		<category><![CDATA[Skip Browser]]></category>
		<category><![CDATA[Skip Page]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=3685</guid>
		<description><![CDATA[There is a common perception that we must include the <code>Browser</code> object in hierarchies when working in the Web environment. The truth is that, we really don't need to include the <code>Browser</code> object <span class="emphasis_u">if</span> the <code>Page</code> object has been included in the hierarchy.]]></description>
			<content:encoded><![CDATA[<p></p><p class="info">
This has been tested to work correctly on QTP versions: 9.5+.
</p>
<p>
There is a common perception that we must include the <code>Browser</code> object in hierarchies when working in the Web environment. The truth is that, we really don&#8217;t need to include the <code>Browser</code> object <span class="emphasis_u">if</span> the <code>Page</code> object has been included in the hierarchy.
</p>
<p>
In other words, the commonly written inline statements for Web environment:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Browser(<span style="color: #800000;">&quot;title:=Google&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=q&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;Test&quot;</span>
Browser(<span style="color: #800000;">&quot;title:=Google&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=q&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;Test&quot;</span></pre></div></div>

<p>
can also be written like this:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Page(<span style="color: #800000;">&quot;title:=Google&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=q&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;Test&quot;</span></pre></div></div>

<p>
Quick tip! Thanks for visiting Relevant Codes! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/browser-not-required/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Regular Expressions and Select Method (ListBox)</title>
		<link>http://relevantcodes.com/regular-expressions-with-select-method-listbox/</link>
		<comments>http://relevantcodes.com/regular-expressions-with-select-method-listbox/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 17:49:56 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/Web]]></category>
		<category><![CDATA[QTP WebList Regex]]></category>
		<category><![CDATA[QTP WebList Regular Expressions]]></category>
		<category><![CDATA[QTP WebList Select]]></category>
		<category><![CDATA[QTP WinComboBox Regex]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[Regular Expressions Select Method]]></category>
		<category><![CDATA[WebList RegEx Select]]></category>
		<category><![CDATA[WebList Select]]></category>
		<category><![CDATA[WinComBoBox Select]]></category>
		<category><![CDATA[WinList Select]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=3433</guid>
		<description><![CDATA[This post describes a few ways to use Regular Expressions to <code>select</code> the target item from List objects. All examples of this post demonstrate techniques to be used in Web Applications, but they can be easily extended to technologies that store all list items with delimiters.]]></description>
			<content:encoded><![CDATA[<p></p><p>
This post describes a few ways to use Regular Expressions to <code>select</code> the target item from List objects. All examples of this post demonstrate techniques to be used in Web Applications, but they can be easily extended to technologies that store all list items with delimiters.
</p>
<h2>Regex Select Using QTP Methods</h2>
<p>
The below method uses QTP&#8217;s technique of retrieving the <code>all items</code> property from the WebList. It also uses RegExp object, which means, regular expressions will be supported. If the pattern does not match the pattern or the exact string from the List, the first item will be selected by default. If the default selection does not fit your requirement, please feel free to modify the code as per your needs.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> RegexSelectQTP(<span style="color: #6666CC; font-weight: bold;">Object</span>, sPattern)
	<span style="color: #0600FF; font-weight: bold;">Dim</span> oRegExp, arrAllItems, ix
&nbsp;
	<span style="color: #008000;">'Create RegExp Object
</span>	<span style="color: #0600FF; font-weight: bold;">Set</span> oRegExp = <span style="color: #0600FF; font-weight: bold;">New</span> RegExp
	oRegExp.IgnoreCase = <span style="color: #0600FF; font-weight: bold;">False</span>
	oRegExp.Pattern = sPattern
&nbsp;
	<span style="color: #008000;">'Split Object's all_items property
</span>	arrAllItems = Split(<span style="color: #6666CC; font-weight: bold;">Object</span>.GetROProperty(<span style="color: #800000;">&quot;all items&quot;</span>), <span style="color: #800000;">&quot;;&quot;</span>)
	<span style="color: #0600FF; font-weight: bold;">For</span> ix = <span style="color: #0600FF; font-weight: bold;">LBound</span>(arrAllItems) <span style="color: #0600FF; font-weight: bold;">To</span> <span style="color: #0600FF; font-weight: bold;">UBound</span>(arrAllItems)
		<span style="color: #008000;">'If RegExp pattern matches list item, we're done!
</span>		<span style="color: #0600FF; font-weight: bold;">If</span> oRegExp.Test(arrAllItems(ix)) <span style="color: #0600FF; font-weight: bold;">Then</span>
			<span style="color: #6666CC; font-weight: bold;">Object</span>.<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;#&quot;</span> &amp;amp; ix
			<span style="color: #0600FF; font-weight: bold;">Set</span> oRegExp = <span style="color: #0600FF; font-weight: bold;">Nothing</span>
			<span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
		<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
	<span style="color: #0600FF; font-weight: bold;">Next</span>
&nbsp;
	<span style="color: #008000;">'Select Item #1 by default
</span>	<span style="color: #6666CC; font-weight: bold;">Object</span>.<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;#0&quot;</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebList&quot;</span>, <span style="color: #800000;">&quot;RegexSelectQTP&quot;</span>, <span style="color: #800000;">&quot;RegexSelectQTP&quot;</span></pre></div></div>

<h5>Usage:</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Browser(<span style="color: #800000;">&quot;&quot;</span>).Page(<span style="color: #800000;">&quot;&quot;</span>).WebList(<span style="color: #800000;">&quot;&quot;</span>).RegexSelectQTP <span style="color: #800000;">&quot;London - Heathrow&quot;</span> <span style="color: #008000;">'Select London-Heathrow
</span>Browser(<span style="color: #800000;">&quot;&quot;</span>).Page(<span style="color: #800000;">&quot;&quot;</span>).WebList(<span style="color: #800000;">&quot;&quot;</span>).RegexSelectQTP <span style="color: #800000;">&quot;London - Heath.*&quot;</span>  <span style="color: #008000;">'Select London-Heathrow
</span>Browser(<span style="color: #800000;">&quot;&quot;</span>).Page(<span style="color: #800000;">&quot;&quot;</span>).WebList(<span style="color: #800000;">&quot;&quot;</span>).RegexSelectQTP <span style="color: #800000;">&quot;London - \D+&quot;</span>      '<span style="color: #0600FF; font-weight: bold;">Select</span> London-Heathrow</pre></div></div>

<h2>Regex Select Using DOM Methods</h2>
<p>
This is quite similar to above, but instead of using the <code>all items</code> property, it uses the HTML DOM <code>options</code>. In general, the HTML of a WebList is like this:
</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:Consolas,Monaco,Courier,Verdana;">&lt;select&gt;
	&lt;option&gt;Acapulco&lt;/option&gt;
	&lt;option&gt;London&lt;/option&gt;
	&lt;option&gt;New York&lt;/option&gt;
	&lt;option&gt;San Francisco&lt;/option&gt;
&lt;/select&gt;</pre></div></div>

<p>
The code below retrieves all the items within the <code>option /option</code> tag and loops through each to determine if there is a regexp match. Also, like the above method, if a match is not found, the first item in the list will be selected by default. <strong>Note:</strong> This method will not work for technologies other than Web.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> RegexSelectDOM(<span style="color: #6666CC; font-weight: bold;">Object</span>, sPattern)
	<span style="color: #0600FF; font-weight: bold;">Dim</span> oRegExp, oOptions, ix
&nbsp;
	<span style="color: #008000;">'Create RegExp Object
</span>	<span style="color: #0600FF; font-weight: bold;">Set</span> oRegExp = <span style="color: #0600FF; font-weight: bold;">New</span> RegExp
	oRegExp.IgnoreCase = <span style="color: #0600FF; font-weight: bold;">False</span>
	oRegExp.Pattern = sPattern
&nbsp;
	<span style="color: #008000;">'DOM options
</span>	<span style="color: #0600FF; font-weight: bold;">Set</span> oOptions = <span style="color: #6666CC; font-weight: bold;">Object</span>.<span style="color: #6666CC; font-weight: bold;">Object</span>.Options
	<span style="color: #0600FF; font-weight: bold;">For</span> ix = 0 <span style="color: #0600FF; font-weight: bold;">to</span> oOptions.Length - 1
		<span style="color: #008000;">'If RegExp pattern matches list item, we're done!
</span>		<span style="color: #0600FF; font-weight: bold;">If</span> oRegExp.Test(oOptions(ix).Text) <span style="color: #0600FF; font-weight: bold;">Then</span>
			<span style="color: #6666CC; font-weight: bold;">Object</span>.<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;#&quot;</span> &amp;amp; ix
			<span style="color: #0600FF; font-weight: bold;">Set</span> oRegExp = <span style="color: #0600FF; font-weight: bold;">Nothing</span>
			<span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
		<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
	<span style="color: #0600FF; font-weight: bold;">Next</span>
&nbsp;
	<span style="color: #008000;">'Select Item #1 by default
</span>	<span style="color: #6666CC; font-weight: bold;">Object</span>.<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;#0&quot;</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebList&quot;</span>, <span style="color: #800000;">&quot;RegexSelectDOM&quot;</span>, <span style="color: #800000;">&quot;RegexSelectDOM&quot;</span></pre></div></div>

<h5>Usage:</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Browser(<span style="color: #800000;">&quot;&quot;</span>).Page(<span style="color: #800000;">&quot;&quot;</span>).WebList(<span style="color: #800000;">&quot;&quot;</span>).RegexSelectDOM <span style="color: #800000;">&quot;London - Heathrow&quot;</span> <span style="color: #008000;">'Select London-Heathrow
</span>Browser(<span style="color: #800000;">&quot;&quot;</span>).Page(<span style="color: #800000;">&quot;&quot;</span>).WebList(<span style="color: #800000;">&quot;&quot;</span>).RegexSelectDOM <span style="color: #800000;">&quot;London - Heath.*&quot;</span>  <span style="color: #008000;">'Select London-Heathrow
</span>Browser(<span style="color: #800000;">&quot;&quot;</span>).Page(<span style="color: #800000;">&quot;&quot;</span>).WebList(<span style="color: #800000;">&quot;&quot;</span>).RegexSelectDOM <span style="color: #800000;">&quot;London - \D+&quot;</span>      '<span style="color: #0600FF; font-weight: bold;">Select</span> London-Heathrow</pre></div></div>

<h2>Select Using VBScript (InStr/Mid) Methods</h2>
<p>
This method does not support Regular Expressions as it is based on VBScript&#8217;s InStr and Mid methods. Instead, it parses the correct value depending upon the supplied complete or partial values without the regexp meta characters.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Function</span> VBSSelect(<span style="color: #6666CC; font-weight: bold;">Object</span>, sString)
	<span style="color: #0600FF; font-weight: bold;">Dim</span> sAllItems, varLocation, varEnd, varBeginning
&nbsp;
	<span style="color: #008000;">'Retrieve Object's all_items property
</span>	sAllItems = <span style="color: #6666CC; font-weight: bold;">Object</span>.GetROProperty(<span style="color: #800000;">&quot;all items&quot;</span>)
&nbsp;
	<span style="color: #008000;">'Verify if the supplied string is found in list's all_items property
</span>	varLocation = InStr(1, sAllItems, sString)
	<span style="color: #008000;">'If found:
</span>	<span style="color: #0600FF; font-weight: bold;">If</span> varLocation &amp;gt; 0 <span style="color: #0600FF; font-weight: bold;">Then</span>
        varEnd = InStr(varLocation, sAllItems, <span style="color: #800000;">&quot;;&quot;</span>)
		<span style="color: #0600FF; font-weight: bold;">If</span> varEnd = 0 <span style="color: #0600FF; font-weight: bold;">Then</span> varEnd = Len(sAllItems) + 1
		varBeginning = InStrRev(sAllItems, <span style="color: #800000;">&quot;;&quot;</span>, varLocation)
		<span style="color: #6666CC; font-weight: bold;">Object</span>.<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;&quot;</span> &amp;amp; Mid(sAllItems, varBeginning + 1, varEnd - varBeginning - 1)
		<span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
	<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
	<span style="color: #008000;">'Select Item #1 by default
</span>	<span style="color: #6666CC; font-weight: bold;">Object</span>.<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;#0&quot;</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
RegisterUserFunc <span style="color: #800000;">&quot;WebList&quot;</span>, <span style="color: #800000;">&quot;VBSSelect&quot;</span>, <span style="color: #800000;">&quot;VBSSelect&quot;</span></pre></div></div>

<h5>Usage:</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Browser(<span style="color: #800000;">&quot;&quot;</span>).Page(<span style="color: #800000;">&quot;&quot;</span>).WebList(<span style="color: #800000;">&quot;&quot;</span>).VBSSelect <span style="color: #800000;">&quot;London - Heathrow&quot;</span> <span style="color: #008000;">'Select London-Heathrow
</span>Browser(<span style="color: #800000;">&quot;&quot;</span>).Page(<span style="color: #800000;">&quot;&quot;</span>).WebList(<span style="color: #800000;">&quot;&quot;</span>).VBSSelect <span style="color: #800000;">&quot;London - Heath&quot;</span>    <span style="color: #008000;">'Select London-Heathrow
</span>Browser(<span style="color: #800000;">&quot;&quot;</span>).Page(<span style="color: #800000;">&quot;&quot;</span>).WebList(<span style="color: #800000;">&quot;&quot;</span>).VBSSelect <span style="color: #800000;">&quot;London - &quot;</span>         '<span style="color: #0600FF; font-weight: bold;">Select</span> London-Heathrow</pre></div></div>

<h2>Performance Comparison</h2>
<p>
The above 3 methods were tested on QTP 10 against a Web Application with 500 iterations each on a Dell XPS M1210 Core2Duo 2.0GHz 3GB Laptop. The table below presents the average time taken by each method to successfully select a value from the WebList in QTP&#8217;s Normal and Fast run modes:
</p>
<table id="table_selectmethods" cellspacing="0" summary="Performance Comparison between Select Methods">
<caption>Performance Comparison between Select Methods</caption>
<tbody>
<tr>
<th class="nobg" scope="col">Run Mode</th>
<th scope="col">Normal</th>
<th scope="col">Fast</th>
</tr>
<tr>
<th class="spec" scope="row">RegexSelectQTP</th>
<td>0.44 seconds</td>
<td>0.38 seconds</td>
</tr>
<tr>
<th class="spec" scope="row">RegexSelectDOM</th>
<td>0.45 seconds</td>
<td>0.40 seconds</td>
</tr>
<tr>
<th class="spec" scope="row">VBSSelect</th>
<td>0.39 seconds</td>
<td>0.35 seconds</td>
</tr>
</tbody>
</table>
<h2></h2>
<p>
If you have written a custom method that you would like to share, please feel free to do so and help the community! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/regular-expressions-with-select-method-listbox/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Automating GMail with QTP</title>
		<link>http://relevantcodes.com/automating-gmail-with-qtp/</link>
		<comments>http://relevantcodes.com/automating-gmail-with-qtp/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 20:30:30 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/Web]]></category>
		<category><![CDATA[GMail Automation]]></category>
		<category><![CDATA[QTP GMail]]></category>
		<category><![CDATA[QTP GMail Automation]]></category>
		<category><![CDATA[QTP GMail Testing]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=2936</guid>
		<description><![CDATA[This article is a tutorial which shows how parts of GMail can be automated through QuickTest Professional. GMail is an extremely dynamic UI and always quite challenging to automate successfully. Its dynamic behavior also makes it an excellent candidate to practice QTP with and sharpen your skills. I will try to show a few techniques that can be helpful in automating GMail, and through it, automating any dynamic application that you encounter.]]></description>
			<content:encoded><![CDATA[<p></p><p>
There are many tutorials that show how QTP methods can be used in everyday test development. However, there are very few lessons available for developers starting in QTP that teach how to automate entire applications, or parts of them. This is such a tutorial and will show how parts of Gmail can be automated through QuickTest Professional. Gmail is an extremely dynamic UI and always quite challenging to automate successfully. Its dynamic behavior also makes it an excellent candidate to practice QTP with and sharpen your skills. I will try to show a few techniques that can be helpful in automating Gmail, and through it, automating any dynamic application that you encounter.
</p>
<h2>Gmail Login</h2>
<p>
I&#8217;m sure everyone who has worked with Gmail would have already created this part of the script and chances are that it would have been created as a function. The same has been done here with the help of  conditional statements:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> GmailLogin(sUserName, sPassword)
    GmailLogin = <span style="color: #0600FF; font-weight: bold;">False</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">With</span> Browser(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>)
        <span style="color: #008000;">'Check if the UserName field exists
</span>        <span style="color: #0600FF; font-weight: bold;">If</span> .WebEdit(<span style="color: #800000;">&quot;html id:=Email&quot;</span>).Exist(0) <span style="color: #0600FF; font-weight: bold;">Then</span>
            .WebEdit(<span style="color: #800000;">&quot;html id:=Email&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Set</span> sUserName    <span style="color: #008000;">'Set UserName
</span>            .WebEdit(<span style="color: #800000;">&quot;html id:=Passwd&quot;</span>).SetSecure sPassword    <span style="color: #008000;">'Set Password
</span>            .WebButton(<span style="color: #800000;">&quot;name:=Sign in&quot;</span>).Click        <span style="color: #008000;">'Click Submit
</span>            .Sync
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
        <span style="color: #008000;">'Check for Link Inbox(xyz)
</span>        <span style="color: #0600FF; font-weight: bold;">If</span> .Link(<span style="color: #800000;">&quot;innertext:=Inbox.*&quot;</span>).Exist(15) <span style="color: #0600FF; font-weight: bold;">Then</span> GMailLogin = <span style="color: #0600FF; font-weight: bold;">True</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">With</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
<span style="color: #008000;">'Usage 1:
</span>MsgBox GmailLogin(<span style="color: #800000;">&quot;yourUserName&quot;</span>, <span style="color: #800000;">&quot;yourPassword&quot;</span>)
&nbsp;
<span style="color: #008000;">'Usage 2:
</span><span style="color: #0600FF; font-weight: bold;">If</span> GmailLogin(<span style="color: #800000;">&quot;yourUserName&quot;</span>, <span style="color: #800000;">&quot;yourPassword&quot;</span>) = <span style="color: #0600FF; font-weight: bold;">True</span> <span style="color: #0600FF; font-weight: bold;">Then</span>
    <span style="color: #008000;">'Continue with test
</span><span style="color: #0600FF; font-weight: bold;">Else</span>
    <span style="color: #008000;">'Stop
</span><span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span></pre></div></div>

<h2>Sign Out of Gmail</h2>
<p>
No tricks here. A simple inline DP or OR statement would accomplish Signing out of Gmail:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Browser(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).Link(<span style="color: #800000;">&quot;innertext:=Sign Out&quot;</span>).Click
&nbsp;
<span style="color: #008000;">'Update March 15, 2011:  The Gmail interface has changed slightly. 
</span><span style="color: #008000;">'If the above does not work, please try this:
</span>Browser(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).Link(<span style="color: #800000;">&quot;innertext:=Sign Out&quot;</span>, <span style="color: #800000;">&quot;class:=gbml1&quot;</span>).Click</pre></div></div>

<h2>Get New Email Count</h2>
<p>
Each automation developer prefers a different approach of retrieving desired values from blocks or text. For each task which requires a value to be retrieved, 3 techniques are demonstrated for the retrieval of expected values: Split, RegExp and Left/Right. But first, we must retrieve the entire string containing the number of Unread emails:
</p>
<p><img class="imgborder" alt="Unread Emails" src="http://relevantcodes.com/Articles/AutomateGMail/Unread.jpg" title="Unread Emails" width="153" height="124" /></p>
<h5>Retrieve &#8216;Inbox (3)&#8217;</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">sLink = Browser(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>).Link(<span style="color: #800000;">&quot;innertext:=Inbox.*&quot;</span>)_
    .GetROProperty(<span style="color: #800000;">&quot;innertext&quot;</span>)</pre></div></div>

<p>
Once the string containing the number of unread e-mails is retrieved, one of the following approaches can be used to produce the same result:
</p>
<h5>Split</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">iEmails = Split(sLink, <span style="color: #800000;">&quot; &quot;</span>)(1) <span style="color: #008000;">'(3)
</span>iEmails = Replace(iEmails, <span style="color: #800000;">&quot;(&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>) <span style="color: #008000;">'3)
</span>iEmails = Replace(iEmails, <span style="color: #800000;">&quot;)&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>) <span style="color: #008000;">'3
</span><span style="color: #0600FF; font-weight: bold;">Print</span> iEmails</pre></div></div>

<h5>RegExp</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">'Updated 03/12/2012
</span><span style="color: #0600FF; font-weight: bold;">Set</span> oRegExp = <span style="color: #0600FF; font-weight: bold;">New</span> RegExp
oRegExp.Global = <span style="color: #0600FF; font-weight: bold;">True</span>
oRegExp.Pattern = <span style="color: #800000;">&quot;\d+&quot;</span>
<span style="color: #0600FF; font-weight: bold;">Set</span> oMatches = oRegExp.Execute(sLink) <span style="color: #008000;">'oMatches(0) = 3
</span>iEmails = oMatches(0)
<span style="color: #0600FF; font-weight: bold;">If</span> oMatches.Count = 2 <span style="color: #0600FF; font-weight: bold;">Then</span> iEmails = iEmails &amp; <span style="color: #800000;">&quot;&quot;</span> &amp; oMatches(1)
<span style="color: #0600FF; font-weight: bold;">Print</span> iEmails</pre></div></div>

<h5>Left, Right</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">iPosition = InStr(1, sLink, <span style="color: #800000;">&quot;(&quot;</span>)
iEmails = Right(sLink, Len(sLink) - iPosition) <span style="color: #008000;">'3
</span>iEmails = Left(iEmails, Len(iEmails) - 1)
<span style="color: #0600FF; font-weight: bold;">Print</span> iEmails</pre></div></div>

<h2>Get Total Emails Count</h2>
<p>
Unlike the scenario above, which retrieved the number of unread e-mails in the AUT, this section shows how the total number of e-mails can be retrieved. Just like the previous scenario, a simple inline DP statement can be used to retrieve the number string that contains the value we are looking for:
</p>
<p><img class="imgborder" alt="Total Emails" src="http://relevantcodes.com/Articles/AutomateGMail/Total.png" title="Total Emails" width="116" height="65" /></p>
<h5>Retrieve &#8217;1 &#8211; 4 of 4&#8242;</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">'Updated 03/15/2012
</span>sText = Browser(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>)_
    .WebElement(<span style="color: #800000;">&quot;innertext:=\d+–\d+ of \d+.*&quot;</span>, <span style="color: #800000;">&quot;index:=0&quot;</span>).GetROProperty(<span style="color: #800000;">&quot;innertext&quot;</span>)
&nbsp;
<span style="color: #008000;">'Alternate:
</span>sText = Browser(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>)_
    .WebElement(<span style="color: #800000;">&quot;class:=J-J5-Ji amH J-JN-I&quot;</span>).GetROProperty(<span style="color: #800000;">&quot;innertext&quot;</span>)</pre></div></div>

<p>
After retrieving the entire string, one of the following approaches can be used to produce the result:
</p>
<h5>Split</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">iEmails = Split(sText, <span style="color: #800000;">&quot;of&quot;</span>)(1) <span style="color: #008000;">' 4
</span>iEmails = Split(iEmails, <span style="color: #800000;">&quot; &quot;</span>)(1) <span style="color: #008000;">'4
</span><span style="color: #0600FF; font-weight: bold;">Print</span> iEmails</pre></div></div>

<h5>RegExp</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">'Updated 03/12/2012
</span><span style="color: #0600FF; font-weight: bold;">Set</span> oRegExp = <span style="color: #0600FF; font-weight: bold;">New</span> RegExp
oRegExp.Global = <span style="color: #0600FF; font-weight: bold;">True</span>
oRegExp.Pattern = <span style="color: #800000;">&quot;of .*&quot;</span>
<span style="color: #0600FF; font-weight: bold;">Set</span> oMatches = oRegExp.Execute(sText)
sMatch = oMatches(oMatches.Count - 1)
&nbsp;
oRegExp.Pattern = <span style="color: #800000;">&quot;\d+&quot;</span>
<span style="color: #0600FF; font-weight: bold;">Set</span> oMatches = oRegExp.Execute(sMatch)
iEmails = oMatches(0)
<span style="color: #0600FF; font-weight: bold;">If</span> oMatches.Count = 2 <span style="color: #0600FF; font-weight: bold;">Then</span> iEmails = iEmails &amp; <span style="color: #800000;">&quot;&quot;</span> &amp; oMatches(1)
<span style="color: #0600FF; font-weight: bold;">Print</span> iEmails</pre></div></div>

<h5>Left, Right</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">iLoc_Of = InStr(1, sText, <span style="color: #800000;">&quot;of&quot;</span>)
iTotals = Right(sText, Len(sText) - iLoc_Of - 1)
iTotals = Trim(iTotals)
<span style="color: #0600FF; font-weight: bold;">Print</span> iTotals</pre></div></div>

<h2>Space Used by Emails</h2>
<p>
One important, and a little complex (in comparison to the above scenarios) one: retrieving the space used by Emails. The process will remain the same, but notice the usage of the wild card character for the WebElement:
</p>
<p><img class="imgborder" alt="Space Used" src="http://relevantcodes.com/Articles/AutomateGMail/Space.png" title="Space Used" width="426" height="69" /></p>
<h5>Retrieve &#8216;You are currently using 0 MB (0%) of your 7430 MB.&#8217;</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">'Updated 03/15/2012
</span>sText = Browser(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>).Page(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>)_
    .WebElement(<span style="color: #800000;">&quot;innertext:=.*Using.*of your.*&quot;</span>, <span style="color: #800000;">&quot;index:=0&quot;</span>)_
    .GetROProperty(<span style="color: #800000;">&quot;innertext&quot;</span>)</pre></div></div>

<p>
The above inline DP statement will retrieve and store the entire string with <code>sText</code>. Once executed, one of the following methods can be used to retrieve the result:
</p>
<h5>Split</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">iSpace = Trim(Split(sText, <span style="color: #800000;">&quot;Using&quot;</span>)(1))
iSpace = Split(iSpace, <span style="color: #800000;">&quot; &quot;</span>)(0) <span style="color: #008000;">'0
</span><span style="color: #0600FF; font-weight: bold;">Print</span> iSpace</pre></div></div>

<h5>RegExp</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">'Updated 03/12/2012
</span><span style="color: #0600FF; font-weight: bold;">Set</span> oRegExp = <span style="color: #0600FF; font-weight: bold;">New</span> RegExp
oRegExp.Pattern = <span style="color: #800000;">&quot;\d+ MB&quot;</span>
<span style="color: #0600FF; font-weight: bold;">Set</span> oMatches = oRegExp.Execute(sText)
iSpace = oMatches(0)
<span style="color: #0600FF; font-weight: bold;">Print</span> iSpace</pre></div></div>

<h5>Left, Right</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">iLoc_MB = InStr(1, sText, <span style="color: #800000;">&quot;MB&quot;</span>)
sText = Trim(Left(sText, iLoc_MB - 1)) <span style="color: #008000;">'You are currently using xx
</span>iSpace = Right(sText, Len(sText) - InStrRev(sText, <span style="color: #800000;">&quot; &quot;</span>)) <span style="color: #008000;">'0
</span><span style="color: #0600FF; font-weight: bold;">Print</span> iSpace</pre></div></div>

<h2>Gmail Auto-Generated Response Message</h2>
<p>
If you would like to check the existence of any of the messages as shown below, accessing the <code>class</code> of the Element will suffice to retrieve the entire text and verify it against our expected result.
</p>
<table style="margin-left:auto; margin-right:auto;">
<tr>
<td style="text-align: center;"><img alt="Message Sent" src="http://relevantcodes.com/Articles/AutomateGMail/MessageSent.png" title="Message Sent" width="246" height="25" /></td>
</tr>
<tr>
<td style="text-align: center;"><img alt="Mark Spam" src="http://relevantcodes.com/Articles/AutomateGMail/MarkSpam.png" title="Mark Spam" width="431" height="27" /></td>
</tr>
<tr>
<td style="text-align: center;"><img alt="Send to Trash" src="http://relevantcodes.com/Articles/AutomateGMail/Trash.png" title="Send to Trash" width="449" height="29" /></td>
</tr>
<tr>
<td style="text-align: center;"><img alt="Undo Spam" src="http://relevantcodes.com/Articles/AutomateGMail/UndoSpam.png" title="Undo Spam" width="603" height="28" /></td>
</tr>
</table>
<p>
Out of the numerous ways these messages could be checked, I am going to show 2 possible uses with a description object and an inline DP statement.
</p>
<h5>Inline DP</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Browser(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>)_
    .WebElement(<span style="color: #800000;">&quot;class:=vh&quot;</span>, <span style="color: #800000;">&quot;html tag:=TD&quot;</span>, <span style="color: #800000;">&quot;index:=0&quot;</span>).GetROProperty(<span style="color: #800000;">&quot;innertext&quot;</span>)</pre></div></div>

<h5>Description Object + ChildObjects</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Dim</span> oDesc, colObject
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Set</span> oDesc = Description.Create
oDesc(<span style="color: #800000;">&quot;micclass&quot;</span>).Value = <span style="color: #800000;">&quot;WebElement&quot;</span>
oDesc(<span style="color: #800000;">&quot;class&quot;</span>).Value = <span style="color: #800000;">&quot;vh&quot;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Set</span> colObject = Browser(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).ChildObjects(oDesc)
&nbsp;
MsgBox colObject(0).GetROProperty(<span style="color: #800000;">&quot;innertext&quot;</span>)</pre></div></div>

<h2>Finding Row with Containing Text</h2>
<p>
To find an e-mail row using text, we can either create a custom function or use the <code>GetRowWithCellText</code> method of the WebTable. However, chances are that the custom function will not prove to be quite as fast. A custom function has been created to find the row containing the specified text:
</p>
<h5>Custom Function</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> FindMailRow(sText)
    <span style="color: #0600FF; font-weight: bold;">Dim</span> oTable, iRows, ix
&nbsp;
    FindMailRow = -1
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">With</span> Browser(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).WebTable(<span style="color: #800000;">&quot;class:=F cf zt&quot;</span>)
        iRows = .GetROProperty(<span style="color: #800000;">&quot;rows&quot;</span>)
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">For</span> ix = 1 <span style="color: #0600FF; font-weight: bold;">to</span> iRows
            sMailText = .GetCellData(ix, 3) &amp; .GetCellData(ix, 5) &amp; .GetCellData(ix, 7)
            <span style="color: #0600FF; font-weight: bold;">If</span> InStr(1, LCase(Replace(sMailText, vbLf, <span style="color: #800000;">&quot; &quot;</span>)), LCase(sText)) <span style="color: #0600FF; font-weight: bold;">Then</span>
                FindMailRow = ix
                <span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
            <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
        <span style="color: #0600FF; font-weight: bold;">Next</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">With</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
<span style="color: #008000;">'Usage:
</span>MsgBox FindMailRow(<span style="color: #800000;">&quot;Text&quot;</span>)</pre></div></div>

<p>
The outcome will be the same when using the <code>GetRowWithCellText</code> method, but with a smaller performance footprint.
</p>
<h5>GetRowWithCellText</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">MsgBox Browser(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).WebTable(<span style="color: #800000;">&quot;class:=F cf zt&quot;</span>)_
    .GetRowWithCellText(<span style="color: #800000;">&quot;Redefining&quot;</span>)</pre></div></div>

<p>
The custom function took <code>2.45 seconds</code> to find the row whereas GetRowWithCellText took only <code>1.22 seconds</code>.
</p>
<h2>Reading Emails</h2>
<p>
The above method can be coupled with a click event to find and open the e-mail that is to be read. A simple inline DP statement can be used to click the target row and open the e-mail. In this example, we&#8217;re going to click on the 2nd Email:
</p>
<p><img class="imgborder" alt="" src="http://relevantcodes.com/Articles/AutomateGMail/ClickEmail.png" title="Clicking the 2nd Row" class="aligncenter" width="751" height="126" /></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">'Updated 03/12/2012
</span><span style="color: #008000;">'I have used 'Access Gmail' but you can use any (unique) text on that row
</span>iRow = Browser(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).WebTable(<span style="color: #800000;">&quot;class:=F cf zt&quot;</span>)_
    .GetRowWithCellText(<span style="color: #800000;">&quot;Access Gmail&quot;</span>)
&nbsp;
<span style="color: #0600FF; font-weight: bold;">With</span> Browser(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>).Page(<span style="color: #800000;">&quot;micclass:=Page&quot;</span>).WebTable(<span style="color: #800000;">&quot;class:=F cf zt&quot;</span>)
    Setting.WebPackage(<span style="color: #800000;">&quot;ReplayType&quot;</span>) = 2
        .ChildItem(iRow, 5, <span style="color: #800000;">&quot;WebElement&quot;</span>, 0).Click
    Setting.WebPackage(<span style="color: #800000;">&quot;ReplayType&quot;</span>) = 1
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">With</span></pre></div></div>

<p>
When the row is clicked, the Email is opened for reading:
</p>
<p><img class="imgborder" alt="Row 2: Access Gmail " src= "http://relevantcodes.com/Articles/AutomateGMail/AccessGmail.jpg" title="Row 2: Access Gmail " width="468" height="120" /></p>
<h2>Compose</h2>
<p>
This can be tricky. Breaking down each component below:
</p>
<h5>Clicking Compose</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Setting.WebPackage(<span style="color: #800000;">&quot;ReplayType&quot;</span>) = 2
    Browser(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>).WebElement(<span style="color: #800000;">&quot;innertext:=COMPOSE&quot;</span>, <span style="color: #800000;">&quot;index:=1&quot;</span>).Click
Setting.WebPackage(<span style="color: #800000;">&quot;ReplayType&quot;</span>) = 1</pre></div></div>

<h5>Recipient, Subject, Body</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">With</span> Browser(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>)
    .WebEdit(<span style="color: #800000;">&quot;html id:=:1b6&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;test@test.com&quot;</span> <span style="color: #008000;">'Recipient
</span>    .WebEdit(<span style="color: #800000;">&quot;html id:=:1c9&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;Subject&quot;</span> <span style="color: #008000;">'Subject
</span>    .WebElement(<span style="color: #800000;">&quot;html id:=:1cl&quot;</span>, <span style="color: #800000;">&quot;index:=1&quot;</span>).<span style="color: #6666CC; font-weight: bold;">Object</span>.innerText = <span style="color: #800000;">&quot;Message Body&quot;</span> <span style="color: #008000;">'Body
</span><span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">With</span></pre></div></div>

<h5>Click Send</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Setting.WebPackage(<span style="color: #800000;">&quot;ReplayType&quot;</span>) = 2
    Browser(<span style="color: #800000;">&quot;title:=Gmail.*&quot;</span>).WebElement(<span style="color: #800000;">&quot;html id:=:1d3&quot;</span>, <span style="color: #800000;">&quot;index:=1&quot;</span>).Click
Setting.WebPackage(<span style="color: #800000;">&quot;ReplayType&quot;</span>) = 1</pre></div></div>

<p>
I hope this article provides more in-depth knowledge of testing complex Web applications. I hope to find more such applications in the future to share with everyone. If you feel there is a scenario that this article lacks, or will become more useful with the addition of one, please do let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/automating-gmail-with-qtp/feed/</wfw:commentRss>
		<slash:comments>132</slash:comments>
		</item>
		<item>
		<title>QTP Browser Methods: .Activate .Maximize .Minimize</title>
		<link>http://relevantcodes.com/qtp-browser-methods-activate-maximize-minimize/</link>
		<comments>http://relevantcodes.com/qtp-browser-methods-activate-maximize-minimize/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 15:42:58 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/Web]]></category>
		<category><![CDATA[Activate Browser]]></category>
		<category><![CDATA[Browser.Activate]]></category>
		<category><![CDATA[Browser.Maximize]]></category>
		<category><![CDATA[Browser.Minimize]]></category>
		<category><![CDATA[BrowserActivate]]></category>
		<category><![CDATA[Maximize Browser]]></category>
		<category><![CDATA[Minimize Browser]]></category>
		<category><![CDATA[QTP RegisterUserFunc]]></category>
		<category><![CDATA[RegisterUserFunc]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=2808</guid>
		<description><![CDATA[This article demonstrates a quick tip to activate, minimize or maximize browsers. Unlike a Standard Windows <code>Window</code> object, Browser <span class="emphasis_u">does not</span> support the <code>Activate</code>, <code>Minimize</code>, <code>Maximize</code> methods. Therefore, we can create our custom function and tie it with the Browser object using <code>RegisterUserFunc</code>.]]></description>
			<content:encoded><![CDATA[<p></p><p>
This article demonstrates a quick tip to activate, minimize or maximize browsers. Unlike a Standard Windows <code>Window</code> object, Browser <span class="emphasis_u">does not</span> support the <code>Activate</code>, <code>Minimize</code>, <code>Maximize</code> methods. Therefore, we can create our custom function and tie it with the Browser object using <code>RegisterUserFunc</code>.
</p>
<p>
The only trick is to retrieve the Browser Handle and substitute the handle in the description of a Window object, and use the Window&#8217;s Activate method instead.
</p>
<h5>Activate Browser</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> BrowserActivate(<span style="color: #6666CC; font-weight: bold;">Object</span>)
    <span style="color: #0600FF; font-weight: bold;">Dim</span> hWnd
&nbsp;
    hWnd = <span style="color: #6666CC; font-weight: bold;">Object</span>.GetROProperty(<span style="color: #800000;">&quot;hwnd&quot;</span>)
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Resume</span> <span style="color: #0600FF; font-weight: bold;">Next</span>
        Window(<span style="color: #800000;">&quot;hwnd:=&quot;</span> &amp; hWnd).Activate
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">If</span> Err.Number &lt;&gt; 0 <span style="color: #0600FF; font-weight: bold;">Then</span>
            Window(<span style="color: #800000;">&quot;hwnd:=&quot;</span> &amp; Browser(<span style="color: #800000;">&quot;hwnd:=&quot;</span> &amp; hWnd).<span style="color: #6666CC; font-weight: bold;">Object</span>.hWnd).Activate
            Err.Clear
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
    <span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Goto</span> 0
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
RegisterUserFunc <span style="color: #800000;">&quot;Browser&quot;</span>, <span style="color: #800000;">&quot;Activate&quot;</span>, <span style="color: #800000;">&quot;BrowserActivate&quot;</span></pre></div></div>

<p>
After registering the <code>BrowserActivate</code> function with the Browser object as <code>Activate</code> we can use it just like we would use it for a Window object:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Browser(<span style="color: #800000;">&quot;title:=Relevant Codes.*&quot;</span>).Activate</pre></div></div>

<p>
<code>BrowserActivate</code> can be extended to maximize and minimize a browser window as well. The only extra statement to be included in the function would be the maximize and minimize methods of the window object.
</p>
<h5>Minimize Browsers</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> BrowserMinimize(<span style="color: #6666CC; font-weight: bold;">Object</span>)
    <span style="color: #0600FF; font-weight: bold;">Dim</span> hWnd
&nbsp;
    hWnd = <span style="color: #6666CC; font-weight: bold;">Object</span>.GetROProperty(<span style="color: #800000;">&quot;hwnd&quot;</span>)
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Resume</span> <span style="color: #0600FF; font-weight: bold;">Next</span>
        Window(<span style="color: #800000;">&quot;hwnd:=&quot;</span> &amp; hWnd).Activate
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">If</span> Err.Number &lt;&gt; 0 <span style="color: #0600FF; font-weight: bold;">Then</span>
            hWnd = Browser(<span style="color: #800000;">&quot;hwnd:=&quot;</span> &amp; hWnd).<span style="color: #6666CC; font-weight: bold;">Object</span>.hWnd
            Window(<span style="color: #800000;">&quot;hwnd:=&quot;</span> &amp; hWnd).Activate
            Err.Clear
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
        Window(<span style="color: #800000;">&quot;hwnd:=&quot;</span> &amp; hWnd).Minimize
    <span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Goto</span> 0
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
RegisterUserFunc <span style="color: #800000;">&quot;Browser&quot;</span>, <span style="color: #800000;">&quot;Minimize&quot;</span>, <span style="color: #800000;">&quot;BrowserMinimize&quot;</span></pre></div></div>

<h5>Maximize Browsers</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> BrowserMaximize(<span style="color: #6666CC; font-weight: bold;">Object</span>)
    <span style="color: #0600FF; font-weight: bold;">Dim</span> hWnd
&nbsp;
    hWnd = <span style="color: #6666CC; font-weight: bold;">Object</span>.GetROProperty(<span style="color: #800000;">&quot;hwnd&quot;</span>)
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Resume</span> <span style="color: #0600FF; font-weight: bold;">Next</span>
        Window(<span style="color: #800000;">&quot;hwnd:=&quot;</span> &amp; hWnd).Activate
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">If</span> Err.Number &lt;&gt; 0 <span style="color: #0600FF; font-weight: bold;">Then</span>
            hWnd = Browser(<span style="color: #800000;">&quot;hwnd:=&quot;</span> &amp; hWnd).<span style="color: #6666CC; font-weight: bold;">Object</span>.hWnd
            Window(<span style="color: #800000;">&quot;hwnd:=&quot;</span> &amp; hWnd).Activate
            Err.Clear
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
        Window(<span style="color: #800000;">&quot;hwnd:=&quot;</span> &amp; hWnd).Maximize
    <span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Goto</span> 0
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
RegisterUserFunc <span style="color: #800000;">&quot;Browser&quot;</span>, <span style="color: #800000;">&quot;Maximize&quot;</span>, <span style="color: #800000;">&quot;BrowserMaximize&quot;</span></pre></div></div>

<p>
If you would like to use the above 3 methods through a single function or class, they can be coupled together through <code>Execute</code> statements or through If-Then or Switch-Case blocks. Happy reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/qtp-browser-methods-activate-maximize-minimize/feed/</wfw:commentRss>
		<slash:comments>58</slash:comments>
		</item>
		<item>
		<title>QTP: Get Link&#8217;s Mouse Over (Hover) Color</title>
		<link>http://relevantcodes.com/qtp-get-links-mouseover-color/</link>
		<comments>http://relevantcodes.com/qtp-get-links-mouseover-color/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 03:28:46 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/Web]]></category>
		<category><![CDATA[Link]]></category>
		<category><![CDATA[Link Color]]></category>
		<category><![CDATA[Link Hover]]></category>
		<category><![CDATA[QTP Link Hover]]></category>
		<category><![CDATA[QTP onMouseOver]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=1889</guid>
		<description><![CDATA[This post describes a simple technique that can enable retrieval of a Link's onMouseOver color by simply changing the ReplayType setting before the onMouseOver FireEvent Event.]]></description>
			<content:encoded><![CDATA[<p></p><p>
This post describes a simple technique that can enable retrieval of a Link&#8217;s onMouseOver color. The only trick is to change the ReplayType setting to Mouse Events while firing an onMouseOver event on the link. Changing the event cause an actual FireEvent action, that you would encounter when you hover the mouse on the link manually.
</p>
<p>
Below, you will see that the hover event is triggered with the ReplayType set to Mouse Events:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Setting.WebPackage(<span style="color: #800000;">&quot;ReplayType&quot;</span>) = 2
Browser(<span style="color: #800000;">&quot;Browser&quot;</span>).Link(<span style="color: #800000;">&quot;Link&quot;</span>).FireEvent <span style="color: #800000;">&quot;onMouseOver&quot;</span>
MsgBox Browser(<span style="color: #800000;">&quot;Browser&quot;</span>).Link(<span style="color: #800000;">&quot;Link&quot;</span>).<span style="color: #6666CC; font-weight: bold;">Object</span>.currentStyle.color
Setting.WebPackage(<span style="color: #800000;">&quot;ReplayType&quot;</span>) = 1</pre></div></div>

<p>
The above snippet can be simplified and be reused using the function below:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> GetHoverColor(oLink)
    Setting.WebPackage(<span style="color: #800000;">&quot;ReplayType&quot;</span>) = 2
        oLink.FireEvent <span style="color: #800000;">&quot;onMouseOver&quot;</span>
        GetHoverColor = oLink.<span style="color: #6666CC; font-weight: bold;">Object</span>.currentStyle.color
    Setting.WebPackage(<span style="color: #800000;">&quot;ReplayType&quot;</span>) = 1
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
RegisterUserFunc <span style="color: #800000;">&quot;Link&quot;</span>, <span style="color: #800000;">&quot;GetHoverColor&quot;</span>, <span style="color: #800000;">&quot;GetHoverColor&quot;</span></pre></div></div>

<p>
Now, whenever the link color is to be retrieved, you can simply call the &#8220;GetHoverColor&#8221; function as you would normally use the Click event:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">MsgBox Browser(<span style="color: #800000;">&quot;Browser&quot;</span>).Page(<span style="color: #800000;">&quot;Page&quot;</span>).Link(<span style="color: #800000;">&quot;Link&quot;</span>).GetHoverColor</pre></div></div>

<p>
I hope you find this useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/qtp-get-links-mouseover-color/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>QTP: Working with Multiple Browser Applications (Revised)</title>
		<link>http://relevantcodes.com/qtp-working-with-multiple-browser-applications-revised/</link>
		<comments>http://relevantcodes.com/qtp-working-with-multiple-browser-applications-revised/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 22:56:17 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/Web]]></category>
		<category><![CDATA[Multiple Browsers]]></category>
		<category><![CDATA[QTP Browsers]]></category>
		<category><![CDATA[QTP IE]]></category>
		<category><![CDATA[QTP Multiple Browsers]]></category>
		<category><![CDATA[QTP Multiple IE]]></category>
		<category><![CDATA[QTP Web]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=1598</guid>
		<description><![CDATA[Web applications due to their dynamic nature, make script development quite challenging. I am writing this article in an attempt to simplify one of its aspects that automation developers face while working with Web applications. We will see how it can be made extremely easy to work with multiple browsers with the use of a Dictionary object, to which we can add Browsers, remove them, change the way we reference them and much more.]]></description>
			<content:encoded><![CDATA[<p></p><div class="photo_right"><a href="http://www.flickr.com/photos/48889097310@N01/454637646/" title="Multiple Browsers"><img src="http://farm1.static.flickr.com/194/454637646_9e735d7f6f_m.jpg" alt="Multiple Browsers"/></a><br /><small><a href="http://creativecommons.org/licenses/by-sa/2.0/" title="Attribution-ShareAlike License"><img src="http://relevantcodes.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" width="16" height="16" /></a> <a href="http://www.photodropper.com/photos/">photo</a> credit: <a href="http://www.flickr.com/photos/48889097310@N01/454637646/" title="Isaac Z. Schlueter" >Isaac Z. Schlueter</a></small></div>
<h2>Introduction</h2>
<p>
Web applications due to their dynamic nature, make script development quite challenging. I am writing this article in an attempt to simplify one of its aspects that automation developers face while working with Web applications. We will see how it can be made extremely easy to work with multiple browsers with the use of a Dictionary object, to which we can add Browsers, remove them, change the way we reference them and much more. </p>
<p>
You will notice in the examples at the end of this article that, regardless of how many pages we navigate, we would never have to keep a track of changing titles (unless we need to). In other words, regardless of browser navigation and actions performed on each browser, this concept will help use the name we give them to work with them, instead of following their ever-changing properties.
</p>
<p>Let&#8217;s begin by creating a global variable, that will hold the Browser Collection to be accessed by our class:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">'Public Variable: Holds Browser Collection
</span><span style="color: #0600FF; font-weight: bold;">Public</span> colBrowser</pre></div></div>

<p>Another reason to create a global variable is that as long as it is an object, it can be used as a reference by (local) class variables, thus being over-written as many number of times as we want. Next, we will create a Browser class, that will make use of the global variable (as a reference) we declared above:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #6666CC; font-weight: bold;">Class</span> clsBrowser
&nbsp;
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Class</span></pre></div></div>

<p>To ensure that we are not creating a new object each time our class initiates, we must create a Singleton, which will be stored in the initialization procedure of our class. It will also assure us that our code is highly efficient and our global variable is created only once, and not destroyed unless required.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">' Purpose: Initializes the Scripting.Dictionary Singleton
</span><span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Initialize</span>
    <span style="color: #0600FF; font-weight: bold;">Dim</span> bInit: bInit = <span style="color: #0600FF; font-weight: bold;">False</span>        
&nbsp;
    <span style="color: #008000;">' If colBrowser has already been instantiated, then Init = True
</span>    <span style="color: #0600FF; font-weight: bold;">If</span> IsObject(colBrowser) <span style="color: #0600FF; font-weight: bold;">Then</span>
        <span style="color: #0600FF; font-weight: bold;">If</span> <span style="color: #0600FF; font-weight: bold;">Not</span> colBrowser <span style="color: #0600FF; font-weight: bold;">Is</span> <span style="color: #0600FF; font-weight: bold;">Nothing</span> <span style="color: #0600FF; font-weight: bold;">Then</span>
            bInit = <span style="color: #0600FF; font-weight: bold;">True</span>
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
    <span style="color: #008000;">' If colBrowser was destroyed or has not yet instantiated, then create it
</span>    <span style="color: #0600FF; font-weight: bold;">If</span> bInit = <span style="color: #0600FF; font-weight: bold;">False</span> <span style="color: #0600FF; font-weight: bold;">Then</span> <span style="color: #0600FF; font-weight: bold;">Set</span> colBrowser = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Scripting.Dictionary&quot;</span>)
&nbsp;
    <span style="color: #008000;">' colObject (local) acts as a reference to colBrowser
</span>    colObject = colBrowser
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span></pre></div></div>

<p>Above, <i>colObject</i> is a reference to our Global Collection object <i>colBrowser</i>.</p>
<p>Instead of creating a new object each time, we will reuse the same reference to add all the necessary Browsers. To add browsers to our collection, let&#8217;s create a simple method called &#8220;AddBrowser&#8221; and a public property &#8220;HWND&#8221;, that will store the Windows Handle of the Browser:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">' Purpose: Adds Browsers and their HWNDs to a Collection
</span><span style="color: #0600FF; font-weight: bold;">Sub</span> AddBrowser(sName)
    <span style="color: #008000;">' If the Name already exists in the collection, then remove it so it can be re-added
</span>    <span style="color: #0600FF; font-weight: bold;">If</span> colObject.Exists(sName) <span style="color: #0600FF; font-weight: bold;">Then</span>
        colObject.Remove sName
        colObject.Remove sName &amp; <span style="color: #800000;">&quot;-HWND&quot;</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
    <span style="color: #008000;">' Add the Browser with its corresponding handle
</span>    <span style="color: #008000;">' Store the Handle Property
</span>    <span style="color: #0600FF; font-weight: bold;">With</span> colObject            
        .Add sName, Browser(<span style="color: #800000;">&quot;hwnd:=&quot;</span> &amp; Me.HWND)
        .Add sName &amp; <span style="color: #800000;">&quot;-HWND&quot;</span>, Me.HWND
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">With</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Private</span> Handle
&nbsp;
<span style="color: #008000;">' Purpose: Stores the Browser Handle
</span><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Let</span> HWND(<span style="color: #0600FF; font-weight: bold;">ByVal</span> Val)
    Handle = val   
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span>
<span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Get</span> HWND()
    HWND = Handle   
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span></pre></div></div>

<h2>AddUsingCreationTime</h2>
<p>
To provide ourselves with more options to add browsers, let&#8217;s create 3 more methods: AddUsingCreationTime, AddUsingTitle and AddLastOpen. As the name suggests, AddUsingCreationTime will enable us to add the browser in our collection object using its creationtime:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">' Purpose: Uses the &quot;AddBrowser&quot; method to add browsers to the collection 
</span><span style="color: #008000;">' using their CreationTime Property
</span><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> AddUsingCreationTime(sName, intCreationTime)
    <span style="color: #0600FF; font-weight: bold;">Dim</span> oBrowser, oCol
&nbsp;
    <span style="color: #008000;">' Description object for Browser Class
</span>    <span style="color: #0600FF; font-weight: bold;">Set</span> oBrowser = Description.Create
    oBrowser(<span style="color: #800000;">&quot;micclass&quot;</span>).Value = <span style="color: #800000;">&quot;Browser&quot;</span>        
&nbsp;
    <span style="color: #008000;">' ChildObjects of Browser Class Description
</span>    <span style="color: #0600FF; font-weight: bold;">Set</span> oCol = Desktop.ChildObjects(oBrowser)
&nbsp;
    <span style="color: #008000;">'If the supplied CreationTime is greater than the total number of open browsers, 
</span>        <span style="color: #008000;">'then Report Err.
</span>    <span style="color: #0600FF; font-weight: bold;">If</span> intVal &gt; oCol.Count <span style="color: #0600FF; font-weight: bold;">Then</span>
        Reporter.ReportEvent micWarning, <span style="color: #800000;">&quot;Add Browser Using CreationTime&quot;</span>, <span style="color: #800000;">&quot;Browser &quot;</span> &amp; _
                <span style="color: #800000;">&quot;with CreationTime &quot;</span> &amp;intCreationTime&amp; <span style="color: #800000;">&quot; was not found.&quot;</span>
        <span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
    <span style="color: #008000;">' Store the Browser Handle
</span>    Me.HWND = Browser(<span style="color: #800000;">&quot;creationtime:=&quot;</span> &amp; intCreationTime).GetROProperty(<span style="color: #800000;">&quot;HWND&quot;</span>)
&nbsp;
    <span style="color: #008000;">' Add the browser to the collection
</span>    AddBrowser sName
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span></pre></div></div>

<h2>AddUsingTitle</h2>
<p>
Similarly, AddUsingTitle will enable us to store a Browser if we prefer using Browser&#8217;s Title:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">' Purpose: Uses the &quot;AddBrowser&quot; method to add browsers to the collection 
</span><span style="color: #008000;">' using their Title Property
</span><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> AddUsingTitle(sName, sTitle)
    <span style="color: #008000;">' Verify if the browser with the supplied title exists
</span>    <span style="color: #0600FF; font-weight: bold;">If</span> <span style="color: #0600FF; font-weight: bold;">Not</span> Browser(<span style="color: #800000;">&quot;title:=&quot;</span> &amp; sTitle).Exist(1) <span style="color: #0600FF; font-weight: bold;">Then</span>
        Reporter.ReportEvent micWarning, <span style="color: #800000;">&quot;Add Browser Using Title&quot;</span>, <span style="color: #800000;">&quot;Browser &quot;</span> &amp; _
                <span style="color: #800000;">&quot;with Title &quot;</span> &amp;sTitle&amp; <span style="color: #800000;">&quot; was not found.&quot;</span>
        <span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
    <span style="color: #008000;">' Store the Browser Handle
</span>    Me.HWND = Browser(<span style="color: #800000;">&quot;title:=&quot;</span> &amp; sTitle).GetROProperty(<span style="color: #800000;">&quot;HWND&quot;</span>)
&nbsp;
    <span style="color: #008000;">' Add the browser to the collection
</span>    AddBrowser sName
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span></pre></div></div>

<h2>AddLastOpen</h2>
<p>
Lastly, for greater flexibility, we will create another method, AddLastOpen, which as the name suggests, will add only the most current browser to our collection:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">' Purpose: Uses the &quot;AddBrowser&quot; method to add the last (most recent) open browser
</span><span style="color: #008000;">'    Note: The last open browser always has the greatest CreationTime
</span><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> AddLastOpen(sName)
    <span style="color: #0600FF; font-weight: bold;">Dim</span> oBrowser, oCol
&nbsp;
    <span style="color: #008000;">' Description object for Browser Class
</span>    <span style="color: #0600FF; font-weight: bold;">Set</span> oBrowser = Description.Create
    oBrowser(<span style="color: #800000;">&quot;micclass&quot;</span>).Value = <span style="color: #800000;">&quot;Browser&quot;</span>        
&nbsp;
    <span style="color: #008000;">' ChildObjects of Browser Class Description
</span>    <span style="color: #0600FF; font-weight: bold;">Set</span> oCol = Desktop.ChildObjects(oBrowser)
&nbsp;
    <span style="color: #008000;">' Store the Browser Handle
</span>    Me.HWND = Browser(<span style="color: #800000;">&quot;creationtime:=&quot;</span> &amp; oCol.Count - 1).GetROProperty(<span style="color: #800000;">&quot;HWND&quot;</span>)
&nbsp;
    <span style="color: #008000;">' Add the browser to the collection
</span>    AddBrowser sName
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span></pre></div></div>

<p>To simplify calling of objects, we will use the names we give to each browser. Instead of using <i>.item</i>, we can use <i>.Name</i> which is more descriptive. This part can be omitted, but for the sake of completion, let&#8217;s create this method anyways:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Function</span> Name(Key)
    <span style="color: #0600FF; font-weight: bold;">Dim</span> Keys
&nbsp;
    Keys = colObject.Keys
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">If</span> IsNumeric(Key) <span style="color: #0600FF; font-weight: bold;">Then</span>
        Key = Keys(Key)
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">If</span> IsObject(colObject.Item(Key)) <span style="color: #0600FF; font-weight: bold;">Then</span>
        <span style="color: #0600FF; font-weight: bold;">Set</span> Name = colObject.Item(Key)
    <span style="color: #0600FF; font-weight: bold;">Else</span>
        Name = colObject.Item(Key)
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span></pre></div></div>

<p>Finally, we must create an instance of the object, that will enable us to call class methods:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">' Create a new instance of Class clsBrowser
</span><span style="color: #0600FF; font-weight: bold;">Set</span> BrowserObject = <span style="color: #0600FF; font-weight: bold;">New</span> clsBrowser</pre></div></div>

<p>We&#8217;re done! You can download the class <a href="http://relevantcodes.com/Articles/MultipleBrowserApps/clsBrowser.zip">here</a>, or view the text version <a href="Http://relevantcodes.com/Articles/MultipleBrowserApps/clsBrowser.txt">here</a></p>
<h2>Demonstration: AddUsingCreationTime</h2>
<p>
As a demonstration, you can associate (or ExecuteFile) the library and run the following lines of code:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">SystemUtil.Run <span style="color: #800000;">&quot;iexplore.exe&quot;</span>, <span style="color: #800000;">&quot;http://newtours.demoaut.com&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, 3 : Wait(4)
<span style="color: #008000;">'Add the First open browser (creationtime=0) to the collection
</span>BrowserObject.AddUsingCreationTime <span style="color: #800000;">&quot;DemoAUT&quot;</span>, 0
&nbsp;
SystemUtil.Run <span style="color: #800000;">&quot;iexplore.exe&quot;</span>, <span style="color: #800000;">&quot;http://relevantcodes.com&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, 3 : Wait(4)
<span style="color: #008000;">'Add the Second open browser (creationtime=1) to the collection
</span>BrowserObject.AddUsingCreationTime <span style="color: #800000;">&quot;RelevantCodes&quot;</span>, 1
&nbsp;
<span style="color: #008000;">'Use the names we gave the browser, and use the same name regardless of changes in its properties
</span><span style="color: #0600FF; font-weight: bold;">With</span> BrowserObject.Name(<span style="color: #800000;">&quot;DemoAUT&quot;</span>)
    .WebEdit(<span style="color: #800000;">&quot;name:=userName&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;test&quot;</span>
    .WebEdit(<span style="color: #800000;">&quot;name:=password&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;test&quot;</span>
    .Image(<span style="color: #800000;">&quot;name:=login&quot;</span>).Click
&nbsp;
    .Sync
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">If</span> .WebList(<span style="color: #800000;">&quot;name:=fromPort&quot;</span>).Exist(10) <span style="color: #0600FF; font-weight: bold;">Then</span>
        .WebList(<span style="color: #800000;">&quot;name:=fromPort&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;Frankfurt&quot;</span>
        .WebList(<span style="color: #800000;">&quot;name:=fromMonth&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;December&quot;</span>
        .WebList(<span style="color: #800000;">&quot;name:=toPort&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;Paris&quot;</span>
        .WebList(<span style="color: #800000;">&quot;name:=toMonth&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;December&quot;</span>
        .WebRadioGroup(<span style="color: #800000;">&quot;name:=servClass&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;#1&quot;</span>
        .WebList(<span style="color: #800000;">&quot;name:=airline&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;Unified Airlines&quot;</span>
        .Image(<span style="color: #800000;">&quot;name:=findFlights&quot;</span>).Click
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">with</span>
&nbsp;
<span style="color: #008000;">'Use the names we gave the browser, and use the same name regardless of changes in its properties
</span><span style="color: #0600FF; font-weight: bold;">With</span> BrowserObject.Name(<span style="color: #800000;">&quot;RelevantCodes&quot;</span>)
    .Link(<span style="color: #800000;">&quot;text:=Articles&quot;</span>, <span style="color: #800000;">&quot;index:=0&quot;</span>).Click
    .Link(<span style="color: #800000;">&quot;text:=Home&quot;</span>, <span style="color: #800000;">&quot;index:=0&quot;</span>).Click
    .Link(<span style="color: #800000;">&quot;text:=QTP\/Web&quot;</span>, <span style="color: #800000;">&quot;index:=0&quot;</span>).Click
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">with</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">With</span> BrowserObject
    .Name(<span style="color: #800000;">&quot;DemoAUT&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Close</span>
    .Name(<span style="color: #800000;">&quot;RelevantCodes&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Close</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">with</span>
&nbsp;
<span style="color: #008000;">'Release
</span>BrowserObject.Destroy</pre></div></div>

<h2>Demonstration: AddUsingTitle</h2>
<p>
As stated earlier, this method will store any browser with the provided title.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">SystemUtil.Run <span style="color: #800000;">&quot;iexplore.exe&quot;</span>, <span style="color: #800000;">&quot;http://newtours.demoaut.com&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, 3 : Wait(4)
<span style="color: #008000;">'Add the above open browser using its title
</span>BrowserObject.AddUsingTitle <span style="color: #800000;">&quot;DemoAUT&quot;</span>, <span style="color: #800000;">&quot;.*Mercury Tours.*&quot;</span>
&nbsp;
SystemUtil.Run <span style="color: #800000;">&quot;iexplore.exe&quot;</span>, <span style="color: #800000;">&quot;http://relevantcodes.com&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, 3 : Wait(4)
<span style="color: #008000;">'Add the above open browser using its title
</span>BrowserObject.AddUsingTitle <span style="color: #800000;">&quot;RelevantCodes&quot;</span>, <span style="color: #800000;">&quot;.*Relevant Codes.*&quot;</span>
&nbsp;
<span style="color: #008000;">'Use the names we gave the browser, and use the same name regardless of changes in its properties
</span><span style="color: #0600FF; font-weight: bold;">With</span> BrowserObject.Name(<span style="color: #800000;">&quot;DemoAUT&quot;</span>)
    .WebEdit(<span style="color: #800000;">&quot;name:=userName&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;test&quot;</span>
    .WebEdit(<span style="color: #800000;">&quot;name:=password&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;test&quot;</span>
    .Image(<span style="color: #800000;">&quot;name:=login&quot;</span>).Click
&nbsp;
    .Sync
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">If</span> .WebList(<span style="color: #800000;">&quot;name:=fromPort&quot;</span>).Exist(10) <span style="color: #0600FF; font-weight: bold;">Then</span>
        .WebList(<span style="color: #800000;">&quot;name:=fromPort&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;Frankfurt&quot;</span>
        .WebList(<span style="color: #800000;">&quot;name:=fromMonth&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;December&quot;</span>
        .WebList(<span style="color: #800000;">&quot;name:=toPort&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;Paris&quot;</span>
        .WebList(<span style="color: #800000;">&quot;name:=toMonth&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;December&quot;</span>
        .WebRadioGroup(<span style="color: #800000;">&quot;name:=servClass&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;#1&quot;</span>
        .WebList(<span style="color: #800000;">&quot;name:=airline&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;Unified Airlines&quot;</span>
        .Image(<span style="color: #800000;">&quot;name:=findFlights&quot;</span>).Click
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">with</span>
&nbsp;
<span style="color: #008000;">'Use the names we gave the browser, and use the same name regardless of changes in its properties
</span><span style="color: #0600FF; font-weight: bold;">With</span> BrowserObject.Name(<span style="color: #800000;">&quot;RelevantCodes&quot;</span>)
    .Link(<span style="color: #800000;">&quot;text:=Articles&quot;</span>, <span style="color: #800000;">&quot;index:=0&quot;</span>).Click
    .Link(<span style="color: #800000;">&quot;text:=Home&quot;</span>, <span style="color: #800000;">&quot;index:=0&quot;</span>).Click
    .Link(<span style="color: #800000;">&quot;text:=QTP\/Web&quot;</span>, <span style="color: #800000;">&quot;index:=0&quot;</span>).Click
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">with</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">With</span> BrowserObject
    .Name(<span style="color: #800000;">&quot;DemoAUT&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Close</span>
    .Name(<span style="color: #800000;">&quot;RelevantCodes&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Close</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">with</span>
&nbsp;
<span style="color: #008000;">'Release
</span>BrowserObject.Destroy</pre></div></div>

<h2>Demonstration: AddLastOpen</h2>
<p>
As stated earlier, this method will add the last open browser to the global browser collection.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">SystemUtil.Run <span style="color: #800000;">&quot;iexplore.exe&quot;</span>, <span style="color: #800000;">&quot;http://newtours.demoaut.com&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, 3 : Wait(4)
<span style="color: #008000;">'Add the last open browser to the collection
</span>BrowserObject.AddLastOpen <span style="color: #800000;">&quot;DemoAUT&quot;</span>
&nbsp;
SystemUtil.Run <span style="color: #800000;">&quot;iexplore.exe&quot;</span>, <span style="color: #800000;">&quot;http://relevantcodes.com&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, 3 : Wait(4)
<span style="color: #008000;">'Add the last open browser to the collection
</span>BrowserObject.AddLastOpen <span style="color: #800000;">&quot;RelevantCodes&quot;</span>
&nbsp;
<span style="color: #008000;">'Use the names we gave the browser, and use the same name regardless of changes in its properties
</span><span style="color: #0600FF; font-weight: bold;">With</span> BrowserObject.Name(<span style="color: #800000;">&quot;DemoAUT&quot;</span>)
    .WebEdit(<span style="color: #800000;">&quot;name:=userName&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;test&quot;</span>
    .WebEdit(<span style="color: #800000;">&quot;name:=password&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;test&quot;</span>
    .Image(<span style="color: #800000;">&quot;name:=login&quot;</span>).Click
&nbsp;
    .Sync
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">If</span> .WebList(<span style="color: #800000;">&quot;name:=fromPort&quot;</span>).Exist(10) <span style="color: #0600FF; font-weight: bold;">Then</span>
        .WebList(<span style="color: #800000;">&quot;name:=fromPort&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;Frankfurt&quot;</span>
        .WebList(<span style="color: #800000;">&quot;name:=fromMonth&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;December&quot;</span>
        .WebList(<span style="color: #800000;">&quot;name:=toPort&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;Paris&quot;</span>
        .WebList(<span style="color: #800000;">&quot;name:=toMonth&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;December&quot;</span>
        .WebRadioGroup(<span style="color: #800000;">&quot;name:=servClass&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;#1&quot;</span>
        .WebList(<span style="color: #800000;">&quot;name:=airline&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #800000;">&quot;Unified Airlines&quot;</span>
        .Image(<span style="color: #800000;">&quot;name:=findFlights&quot;</span>).Click
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">with</span>
&nbsp;
<span style="color: #008000;">'Use the names we gave the browser, and use the same name regardless of changes in its properties
</span><span style="color: #0600FF; font-weight: bold;">With</span> BrowserObject.Name(<span style="color: #800000;">&quot;RelevantCodes&quot;</span>)
    .Link(<span style="color: #800000;">&quot;text:=Articles&quot;</span>, <span style="color: #800000;">&quot;index:=0&quot;</span>).Click
    .Link(<span style="color: #800000;">&quot;text:=Home&quot;</span>, <span style="color: #800000;">&quot;index:=0&quot;</span>).Click
    .Link(<span style="color: #800000;">&quot;text:=QTP\/Web&quot;</span>, <span style="color: #800000;">&quot;index:=0&quot;</span>).Click
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">with</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">With</span> BrowserObject
    .Name(<span style="color: #800000;">&quot;DemoAUT&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Close</span>
    .Name(<span style="color: #800000;">&quot;RelevantCodes&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Close</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">with</span>
&nbsp;
<span style="color: #008000;">'Release
</span>BrowserObject.Destroy</pre></div></div>

<p>Notice the demos above. We only have to use the custom name we gave to the browser to perform events on the objects that exist inside of it. Our custom names can be used throughout the automation cycle, but I would recommend you to look into the &#8220;ChangeName&#8221; method available in the class. This would make object naming easier, and more descriptive, as the titles change the moment we navigate to another page.</p>
<p class="centeralign th-box download">
<a href="http://relevantcodes.com/Articles/MultipleBrowserApps/clsBrowser.zip">Download clsBrowser</a> | <a href="http://relevantcodes.com/Articles/MultipleBrowserApps/clsBrowser.txt">View as Plain Text</a> | <a href="http://relevantcodes.com/Articles/MultipleBrowserApps/BrowserDemo92.zip">Download Demo Test QTP9.2</a> | <a href="http://relevantcodes.com/Articles/MultipleBrowserApps/BrowserDemo95.zip">Download Demo Test QTP9.5</a></p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/qtp-working-with-multiple-browser-applications-revised/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>QTP: Working with Multiple Browser Applications &#8211; A Concept</title>
		<link>http://relevantcodes.com/qtp-working-with-multiple-browser-applications-a-concept/</link>
		<comments>http://relevantcodes.com/qtp-working-with-multiple-browser-applications-a-concept/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 23:26:40 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/Web]]></category>
		<category><![CDATA[Browser]]></category>
		<category><![CDATA[Classes]]></category>
		<category><![CDATA[Dictionary]]></category>
		<category><![CDATA[Multiple Browsers]]></category>
		<category><![CDATA[QTP Applications]]></category>
		<category><![CDATA[QTP Multiple Browsers]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=643</guid>
		<description><![CDATA[This article demonstrates an elegant approach to working with multiple Browsers through the use of Classes and Dictionary Object. Examples included.]]></description>
			<content:encoded><![CDATA[<p></p><div class="photo_right"><a href="http://www.flickr.com/photos/48889097310@N01/454637646/" title="Multiple Browsers"><img src="http://farm1.static.flickr.com/194/454637646_9e735d7f6f_m.jpg" alt="Multiple Browsers"/></a><br /><small><a href="http://creativecommons.org/licenses/by-sa/2.0/" title="Attribution-ShareAlike License"><img src="http://relevantcodes.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" width="16" height="16" /></a> <a href="http://www.photodropper.com/photos/">photo</a> credit: <a href="http://www.flickr.com/photos/48889097310@N01/454637646/" title="Isaac Z. Schlueter" >Isaac Z. Schlueter</a></small></div>
<p><strong>Introduction</strong><br />
Web applications due to their dynamic nature, make script development quite challenging. I am writing this article in an attempt to simplify one of its aspects that automation developers face while working with Web applications. We will see how it can be made extremely easy to work with multiple browsers with the use of a Dictionary object, to which we can add Browsers, remove them, change their description etc. You will notice in the example at the end of this article that, regardless of how many pages we navigate, we would never have to keep a track of changing titles (unless we need to). </p>
<p>Let&#8217;s begin by creating a global variable, that will hold the Browser Collection to be accessed by our class:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">'Public Variable: Browser Collection
</span><span style="color: #0600FF; font-weight: bold;">Public</span> colBrowser</pre></div></div>

<p>Another reason to create a global variable is that as long as it is an object, it can be used as a reference by (local) class variables, thus being over-written as many number of times as we want. Next, we will create a Browser class, that will make use of the global variable (as a reference) we declared above:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #6666CC; font-weight: bold;">Class</span> clsBrowser
&nbsp;
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Class</span></pre></div></div>

<p>To ensure that we are not creating a new object each time our class initiates, we must create a Singleton, which will be stored in the initialization procedure of our class. It will also assure us that our code is highly efficient and our global variable is created only once, and not destroyed unless required.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">' Purpose: Initializes the Scripting.Dictionary Singleton
</span><span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Initialize</span>
	<span style="color: #0600FF; font-weight: bold;">Dim</span> bInit: bInit = <span style="color: #0600FF; font-weight: bold;">False</span>		
&nbsp;
	<span style="color: #008000;">' If colBrowser has already been instantiated, then Init = True
</span>	<span style="color: #0600FF; font-weight: bold;">If</span> IsObject(colBrowser) <span style="color: #0600FF; font-weight: bold;">Then</span>
		<span style="color: #0600FF; font-weight: bold;">If</span> <span style="color: #0600FF; font-weight: bold;">Not</span> colBrowser <span style="color: #0600FF; font-weight: bold;">Is</span> <span style="color: #0600FF; font-weight: bold;">Nothing</span> <span style="color: #0600FF; font-weight: bold;">Then</span>
			bInit = <span style="color: #0600FF; font-weight: bold;">True</span>
		<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
	<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
	<span style="color: #008000;">' If colBrowser was destroyed or has not yet instantiated, then create it
</span>	<span style="color: #0600FF; font-weight: bold;">If</span> bInit = <span style="color: #0600FF; font-weight: bold;">False</span> <span style="color: #0600FF; font-weight: bold;">Then</span> <span style="color: #0600FF; font-weight: bold;">Set</span> colBrowser = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Scripting.Dictionary&quot;</span>)
&nbsp;
	<span style="color: #008000;">' colObject (local) acts as a reference to colBrowser
</span>	colObject = colBrowser
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span></pre></div></div>

<p>Above, <i>colObject</i> is a reference to our Global Collection object <i>colBrowser</i>. To ensure that the reference isn&#8217;t lost while being accessed by Class members, let&#8217;s make it a read/write property:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Private</span> m_hashTable
&nbsp;
<span style="color: #008000;">' Purpose: Stores the colObject Object to be accessed by Class members
</span><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Let</span> colObject(<span style="color: #0600FF; font-weight: bold;">ByRef</span> Val)
	<span style="color: #0600FF; font-weight: bold;">Set</span> m_hashTable = Val
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span>
<span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Get</span> colObject()
	<span style="color: #0600FF; font-weight: bold;">Set</span> colObject = m_hashTable
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span></pre></div></div>

<p>Instead of creating a new object each time, we will reuse the same reference to add all the necessary Browsers. To add browsers to our collection, let&#8217;s create a simple method called &#8220;AddBrowser&#8221; and a public property &#8220;HWND&#8221;, that will store the Windows Handle of the Browser:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">' Purpose: Adds Browsers and their HWNDs to a Collection
</span><span style="color: #0600FF; font-weight: bold;">Sub</span> AddBrowser(sName)
	<span style="color: #008000;">' If the Name already exists in the collection, then remove it so it can be re-added
</span>	<span style="color: #0600FF; font-weight: bold;">If</span> colObject.Exists(sName) <span style="color: #0600FF; font-weight: bold;">Then</span>
		colObject.Remove sName
		colObject.Remove sName &amp; <span style="color: #800000;">&quot;-HWND&quot;</span>
	<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
	<span style="color: #008000;">' Add the Browser with its corresponding handle
</span>	<span style="color: #008000;">' Store the Handle Property
</span>	<span style="color: #0600FF; font-weight: bold;">With</span> colObject			
		.Add sName, Browser(<span style="color: #800000;">&quot;hwnd:=&quot;</span> &amp; Me.HWND)
		.Add sName &amp; <span style="color: #800000;">&quot;-HWND&quot;</span>, Me.HWND
	<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">With</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Private</span> Handle
&nbsp;
<span style="color: #008000;">' Purpose: Stores the Browser Handle
</span><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Let</span> HWND(<span style="color: #0600FF; font-weight: bold;">ByVal</span> Val)
	Handle = val   
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span>
<span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Get</span> HWND()
	HWND = Handle   
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span></pre></div></div>

<p>To provide ourselves with more options to add browsers, let&#8217;s create 3 more methods: AddUsingCreationTime, AddUsingTitle and AddLastOpen. As the name suggests, AddUsingCreationTime will enable us to add the browser in our collection object using its creationtime:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">' Purpose: Uses the &quot;AddBrowser&quot; method to add browsers to the collection 
</span><span style="color: #008000;">' using their CreationTime Property
</span><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> AddUsingCreationTime(sName, intVal)
	<span style="color: #0600FF; font-weight: bold;">Dim</span> oBrowser, oCol
&nbsp;
	<span style="color: #008000;">' Description object for Browser Class
</span>	<span style="color: #0600FF; font-weight: bold;">Set</span> oBrowser = Description.Create
	oBrowser(<span style="color: #800000;">&quot;micclass&quot;</span>).Value = <span style="color: #800000;">&quot;Browser&quot;</span>		
&nbsp;
	<span style="color: #008000;">' ChildObjects of Browser Class Description
</span>	<span style="color: #0600FF; font-weight: bold;">Set</span> oCol = Desktop.ChildObjects(oBrowser)
&nbsp;
	<span style="color: #008000;">' If the supplied CreationTime is greater than the total number of open browsers, 
</span>	<span style="color: #008000;">' then Report Err.
</span>	<span style="color: #0600FF; font-weight: bold;">If</span> intVal &gt; oCol.Count <span style="color: #0600FF; font-weight: bold;">Then</span>
		Reporter.ReportEvent micWarning, <span style="color: #800000;">&quot;Add Browser Using CreationTime&quot;</span>,_
		<span style="color: #800000;">&quot;Browser with CreationTime &quot;</span> &amp;intVal&amp; <span style="color: #800000;">&quot; was not found.&quot;</span>
		<span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
	<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
	<span style="color: #008000;">' Store the Browser Handle
</span>	Me.HWND = Browser(<span style="color: #800000;">&quot;creationtime:=&quot;</span> &amp; intVal).GetROProperty(<span style="color: #800000;">&quot;HWND&quot;</span>)
&nbsp;
	<span style="color: #008000;">' Add the browser to the collection
</span>	AddBrowser sName
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span></pre></div></div>

<p>Similarly, AddUsingTitle will enable us to store a Browser if we prefer using Browser&#8217;s Title:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">' Purpose: Uses the &quot;AddBrowser&quot; method to add browsers to the collection 
</span><span style="color: #008000;">' using their Title Property
</span><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> AddUsingTitle(sName, sTitle)
	<span style="color: #008000;">' Verify if the browser with the supplied title exists
</span>	<span style="color: #0600FF; font-weight: bold;">If</span> <span style="color: #0600FF; font-weight: bold;">Not</span> Browser(<span style="color: #800000;">&quot;title:=&quot;</span> &amp; sTitle).Exist(1) <span style="color: #0600FF; font-weight: bold;">Then</span>
		Reporter.ReportEvent micWarning, <span style="color: #800000;">&quot;Add Browser Using Title&quot;</span>, _
		<span style="color: #800000;">&quot;Browser with Title &quot;</span> &amp;sTitle&amp; <span style="color: #800000;">&quot; was not found.&quot;</span>
		<span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
	<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
	<span style="color: #008000;">' Store the Browser Handle
</span>	Me.HWND = Browser(<span style="color: #800000;">&quot;creationtime:=&quot;</span> &amp; intVal).GetROProperty(<span style="color: #800000;">&quot;HWND&quot;</span>)
&nbsp;
	<span style="color: #008000;">' Add the browser to the collection
</span>	AddBrowser sName
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span></pre></div></div>

<p>Lastly, for greater flexibility, we will create another method, AddLastOpen, which as the name suggests, will add only the most current browser to our collection:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">' Purpose: Uses the &quot;AddBrowser&quot; method to add the last (most recent) open browser
</span><span style="color: #008000;">'	Note: The last open browser always has the greatest CreationTime
</span><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> AddLastOpen(sName)
	<span style="color: #0600FF; font-weight: bold;">Dim</span> oBrowser, oCol
&nbsp;
	<span style="color: #008000;">' Description object for Browser Class
</span>	<span style="color: #0600FF; font-weight: bold;">Set</span> oBrowser = Description.Create
	oBrowser(<span style="color: #800000;">&quot;micclass&quot;</span>).Value = <span style="color: #800000;">&quot;Browser&quot;</span>		
&nbsp;
	<span style="color: #008000;">' ChildObjects of Browser Class Description
</span>	<span style="color: #0600FF; font-weight: bold;">Set</span> oCol = Desktop.ChildObjects(oBrowser)
&nbsp;
	<span style="color: #008000;">' Store the Browser Handle
</span>	Me.HWND = Browser(<span style="color: #800000;">&quot;creationtime:=&quot;</span> &amp; oCol.Count - 1).GetROProperty(<span style="color: #800000;">&quot;HWND&quot;</span>)
&nbsp;
	<span style="color: #008000;">' Add the browser to the collection
</span>	AddBrowser sName
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span></pre></div></div>

<p>To simplify calling of objects, lets create a method named &#8216;Name&#8217; which will work directly with our Dictionary using its methods:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Function</span> Name(Key)
	<span style="color: #0600FF; font-weight: bold;">Dim</span> Keys
&nbsp;
	Keys = colObject.Keys
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">If</span> IsNumeric(Key) <span style="color: #0600FF; font-weight: bold;">Then</span>
		Key = Keys(Key)
	<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">If</span> IsObject(colObject.Item(Key)) <span style="color: #0600FF; font-weight: bold;">Then</span>
		<span style="color: #0600FF; font-weight: bold;">Set</span> Name = colObject.Item(Key)
	<span style="color: #0600FF; font-weight: bold;">Else</span>
		Name = colObject.Item(Key)
	<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span></pre></div></div>

<p>Finally, we must create an instance of the object, that will enable us to call class methods:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">' Create a new instance of Class clsBrowser
</span><span style="color: #0600FF; font-weight: bold;">Set</span> BrowserObject = <span style="color: #0600FF; font-weight: bold;">New</span> clsBrowser</pre></div></div>

<p>We&#8217;re done! You can download the class <a href="http://relevantcodes.com/Articles/MultipleBrowserApps/MultipleBrowserApps.zip">here</a>, or view the text version <a href="Http://relevantcodes.com/Articles/MultipleBrowserApps/MultipleBrowserApps.txt">here</a></p>
<p><strong>Demonstration</strong><br />
As a demonstration, you can associate (or ExecuteFile) the library and run the following lines of code:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">' Launch 2 Browsers:
</span><span style="color: #008000;">'	1. Google Home (HOME)
</span><span style="color: #008000;">' 	2. Google Maps (MAPS)
</span><span style="color: #0600FF; font-weight: bold;">With</span> SystemUtil
	.Run <span style="color: #800000;">&quot;iexplore.exe&quot;</span>, <span style="color: #800000;">&quot;www.google.com&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, 3 : Wait(2)
	.Run <span style="color: #800000;">&quot;iexplore.exe&quot;</span>, <span style="color: #800000;">&quot;maps.google.com&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, 3 : Wait(2)
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">With</span>
&nbsp;
<span style="color: #008000;">' Add the 2 open browsers
</span><span style="color: #008000;">'	1. Add Google Home using its creationTime
</span><span style="color: #008000;">'	2. Add Google Maps using the .AddLastOpen Method (Since GoogleMaps is the last open
</span><span style="color: #008000;">'		browser, it will have the highest CreationTime. In other words, its the most 
</span><span style="color: #008000;">'		current open browser)
</span><span style="color: #0600FF; font-weight: bold;">With</span> BrowserObject
	.AddUsingCreationTime <span style="color: #800000;">&quot;HOME&quot;</span>, 0
	.AddLastOpen <span style="color: #800000;">&quot;MAPS&quot;</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">With</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">With</span> BrowserObject
	<span style="color: #008000;">' Highlight and output the title of the &quot;HOME&quot; browser (it has a creationtime of 0)
</span>	.Name(<span style="color: #800000;">&quot;HOME&quot;</span>).Highlight
&nbsp;
	MsgBox <span style="color: #800000;">&quot;Title: &quot;</span> &amp; .Name(<span style="color: #800000;">&quot;HOME&quot;</span>).GetROProperty(<span style="color: #800000;">&quot;title&quot;</span>)
&nbsp;
	<span style="color: #008000;">'Set search text
</span>	.Name(<span style="color: #800000;">&quot;HOME&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=q&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;Google Home&quot;</span>
	<span style="color: #008000;">'Click Google Search
</span>	.Name(<span style="color: #800000;">&quot;HOME&quot;</span>).WebButton(<span style="color: #800000;">&quot;name:=Google Search&quot;</span>).Click
	<span style="color: #008000;">' You never have to worry about changing Titles/object properties
</span>	.Name(<span style="color: #800000;">&quot;HOME&quot;</span>).Back
&nbsp;
	<span style="color: #008000;">' Highlight and output the title of the &quot;MAPS&quot; browser (it is the last open browser)
</span>	.Name(<span style="color: #800000;">&quot;MAPS&quot;</span>).Highlight
&nbsp;
	MsgBox <span style="color: #800000;">&quot;Title: &quot;</span> &amp; .Name(<span style="color: #800000;">&quot;MAPS&quot;</span>).GetROProperty(<span style="color: #800000;">&quot;title&quot;</span>)
&nbsp;
	<span style="color: #008000;">' Close MAPS Browser
</span>	.Name(<span style="color: #800000;">&quot;MAPS&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Close</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">With</span>
&nbsp;
<span style="color: #008000;">'Release Dictionary
</span>BrowserObject.Destroy</pre></div></div>

<p>Notice the demo above. We only have to use the custom name we gave to the browser to perform events on the objects that exist inside of it. Our custom names can be used throughout the automation cycle, but I would recommend you to look into the &#8220;ChangeName&#8221; method available in the class and included in the <a href="http://relevantcodes.com/Articles/MultipleBrowserApps/Demo.zip">QTP test</a>, that you can download. This would make object naming easier, and more descriptive, as the titles change the moment we navigate to another page.</p>
<p><a href="http://relevantcodes.com/Articles/MultipleBrowserApps/MultipleBrowserApps.zip">Download the Class: clsBrowser</a></p>
<p>If you would like very high-level demo of this class, you can <a href="http://relevantcodes.com/Articles/MultipleBrowserApps/Demo.zip">download the demo QTP test</a> as well.</p>
<p>If you need more examples, or clarification on any of the concepts mentioned in this article, please let me know! Also, if you feel this class can be improved further by adding some interesting methods, then we&#8217;ll surely work together to incorporate them.</p>
<p><strong>References</strong></p>
<ol>
<li><a href="http://www.advancedqtp.com/knowledge-base/articles/code-techniques-id15/data-structures-id16/an-improved-dictionary-object/">An Improved Dictionary Object</a> by Yaron Assa (AdvancedQTP, SolmarKN)</li>
<li><a href="http://www.advancedqtp.com/knowledge-base/articles/code-techniques-id15/code-design-id16/design-patterns-id30/singleton-pattern/ ">Singleton Pattern</a> by Yaron Assa (AdvancedQTP, SolmarKN) </li>
</ol>
<p class="alert">If you have any questions, please ask them in the comments section. If your query is confidential, please use the <a href="http://relevantcodes.com/contact/">Contact Form</a> to send me an e-mail instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/qtp-working-with-multiple-browser-applications-a-concept/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 9/56 queries in 0.054 seconds using disk: basic
Object Caching 755/903 objects using disk: basic
Content Delivery Network via N/A

Served from: relevantcodes.com @ 2012-05-19 10:50:36 -->
