How to get the current browser name

Class library usage, coding and language questions.
kumarm100
Posts: 7
Joined: Mon Apr 05, 2010 1:04 pm

How to get the current browser name

Post by kumarm100 » Mon May 24, 2010 8:53 am

Hi,
Please let me know how to get the current loaded browser name asap
Regards
Kumar

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to get the current browser name

Post by Support Team » Mon May 24, 2010 10:48 am

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

kumarm100
Posts: 7
Joined: Mon Apr 05, 2010 1:04 pm

Re: How to get the current browser name

Post by kumarm100 » Mon May 24, 2010 11:12 am

Hi Christian,
Thanks for your reply. Is there any other way to identify the browser name without declaring the path in webdocument.

Regards
Kumar

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: How to get the current browser name

Post by Ciege » Mon May 24, 2010 4:54 pm

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.
}

If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to get the current browser name

Post by Support Team » Tue May 25, 2010 11:53 am

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

kumarm100
Posts: 7
Joined: Mon Apr 05, 2010 1:04 pm

Re: How to get the current browser name

Post by kumarm100 » Wed May 26, 2010 1:08 pm

Thank you all for your reply, i will try and get back to you

kumarm100
Posts: 7
Joined: Mon Apr 05, 2010 1:04 pm

Re: How to get the current browser name

Post by kumarm100 » Sun Jun 20, 2010 2:15 am

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();
}