How to get the current browser name : Automation API

How to get the current browser name

Class library usage, coding and language questions.

How to get the current browser name

Postby kumarm100 » Mon May 24, 2010 9:53 am

Hi,
Please let me know how to get the current loaded browser name asap
Regards
Kumar
kumarm100
 
Posts: 7
Joined: Mon Apr 05, 2010 2:04 pm

Re: How to get the current browser name

Postby Support Team » Mon May 24, 2010 11: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
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: How to get the current browser name

Postby kumarm100 » Mon May 24, 2010 12:12 pm

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

Regards
Kumar
kumarm100
 
Posts: 7
Joined: Mon Apr 05, 2010 2:04 pm

Re: How to get the current browser name

Postby Ciege » Mon May 24, 2010 5: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
Ciege
 
Posts: 965
Joined: Thu Oct 16, 2008 7:46 pm
Location: Arizona, USA

Re: How to get the current browser name

Postby Support Team » Tue May 25, 2010 12:53 pm

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
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: How to get the current browser name

Postby kumarm100 » Wed May 26, 2010 2:08 pm

Thank you all for your reply, i will try and get back to you
kumarm100
 
Posts: 7
Joined: Mon Apr 05, 2010 2:04 pm

Re: How to get the current browser name

Postby kumarm100 » Sun Jun 20, 2010 3: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();
}
kumarm100
 
Posts: 7
Joined: Mon Apr 05, 2010 2:04 pm


Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests