Page 1 of 1

URL name dynamically

Posted: Mon Aug 29, 2011 3:20 pm
by Praveen597
Hi All,

I'm new to Ranorex. But I found something interesting with it so I decided to explore the tool.

Can any one explain how to get the URL name dynamically of all currently running browsers using C# code in Ranorex.

Re: URL name dynamically

Posted: Mon Aug 29, 2011 4:24 pm
by Ciege
Take a look at this post... With just a small bit of tweaking you can modify the code to return all the URLs of any open browser.

http://www.ranorex.com/forum/how-to-fin ... t1032.html

Re: URL name dynamically

Posted: Tue Aug 30, 2011 10:46 am
by Praveen597
Thank you Ceige,

After many attempts I got the trick. As I am a begineer, I am getting lots of doubts so kindly please bare with me.

I used:

System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName("iexplore");
foreach(System.Diagnostics.Process Ps in p)
{
Ps.Kill();
}

and also the below code doing the same thing:
List<Ranorex.WebDocument> AllDoms = Host.Local.FindChildren<Ranorex.WebDocument>();
if (AllDoms.Count >=1
{
foreach (WebDocument myDom in AllDoms)
{
myDom.Close();
}
}

Which one is better...? Is there any other method to do the same...?

And one more thing , hoe to get the URL of the browser dynamically....

Re: URL name dynamically

Posted: Tue Aug 30, 2011 3:38 pm
by Ciege
Which one is better...?
Not sure which is better, I use the .Close method instead of the .Kill method. I'm not sure what .Kill does under the covers and my just force kill the process found rather than cleanly close...?
And one more thing , hoe to get the URL of the browser dynamically....
Using the second method, instead of doing a myDom.Close(); you can get the PageUrl property from each myDom.

Re: URL name dynamically

Posted: Tue Aug 30, 2011 7:51 pm
by Support Team
The template parameter (<Ranorex.WebDocument>) does only do a type casting over all children.
The actual element you best find with either <adapter>.Find() or <adapter>.FindSingle() and a RanorexPath.
The first gives you all the element that fit to the provided path, the second gives you the first one.
You would use a path that is relative to the adapter class you use.
In your case you start with the adapter that represents your desktop (Host.Local).
Then you can use an absolute path.
IList<Ranorex.WebDocument> AllDoms = Host.Local.Find<Ranorex.WebDocument>("/dom");
foreach (WebDocument myDom in AllDoms)
{
	myDom.Close();
}
Regards,
Roland
Ranorex Support Team