Page 1 of 1

How to get the current browser name

Posted: Mon May 24, 2010 8:53 am
by kumarm100
Hi,
Please let me know how to get the current loaded browser name asap
Regards
Kumar

Re: How to get the current browser name

Posted: Mon May 24, 2010 10:48 am
by Support Team
Hi Kumar!
Use the BrowserName property from the WebDocument class.

example code:
WebDocument webDocument = "Path/To/the/browser/DOM";
string browserName = webDocument.BrowserName;
Best regards,
Christian
Ranorex Team

Re: How to get the current browser name

Posted: Mon May 24, 2010 11:12 am
by kumarm100
Hi Christian,
Thanks for your reply. Is there any other way to identify the browser name without declaring the path in webdocument.

Regards
Kumar

Re: How to get the current browser name

Posted: Mon May 24, 2010 4:54 pm
by Ciege
Do you have more than one browser open or just a single browser?

Regardless, you can get an IList of all the forms displayed on the host then iterate the list searching for either the only browser or a browser that happens to have context.

Something like this. Keep in mind this is not tested code but an example I just wrote up here:

Code: Select all

IList<Ranorex.Form> AllForms = Host.Local.FindChildren<Ranorex.Form>();
foreach (Ranorex.Form ThisForm in AllForms )
{
  //here search for the property of the web document to determine if it is the one you want. 
  //If so break out of the loop and use the ThisForm object as your form.
}


Re: How to get the current browser name

Posted: Tue May 25, 2010 11:53 am
by Support Team
kumarm100 wrote:Is there any other way to identify the browser name without declaring the path in webdocument.
Sure, for a given web element you can use a RanoreXPath to find its parent/ancestor DOM element and then get the browser name from that element:
WebElement webElement;
WebDocument doc = webElement.FindSingle<WebDocument>("ancestor-or-self::dom");
string browserName = doc.BrowserName;
Regards,
Alex
Ranorex Team

Re: How to get the current browser name

Posted: Wed May 26, 2010 1:08 pm
by kumarm100
Thank you all for your reply, i will try and get back to you

Re: How to get the current browser name

Posted: Sun Jun 20, 2010 2:15 am
by kumarm100
Hi All,
I was able to check the browser and activate by the following way

webdocument wb = null;
if(wb.pageurl.tostring().contains("Home"))
{
wb.browser.activate();
}