How to get tab index using ranorex

Best practices, code snippets for common functionality, examples, and guidelines.
AnithaKarthik
Posts: 3
Joined: Mon May 09, 2016 10:20 pm

How to get tab index using ranorex

Post by AnithaKarthik » Thu May 26, 2016 6:47 pm

if we have multiple tabs opened in a browser, how to get the list of browser tabs and how do we get the handle of each browser tab. This way i should be able to get the tab count. Is there any way i can find using ranorex xpath through code?

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3932
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to get tab index using ranorex

Post by odklizec » Fri May 27, 2016 9:10 am

Hi,

Each browser has it's own implementation of tabs, so you will have to create a separate repo item for each browser. Eventually, you can try to create a generic one, applicable to all browsers, but it may make the search for tabs a bit slow?

Then you can use code like this, to obtain all tabs returned by given repo element, get tab count and do whatever you want with them...

Code: Select all

		public void GetListOfTabs(Ranorex.Core.Repository.RepoItemInfo repoItemInfo)
		{
			// Create a list of adapters using the "Info" object
			IList<Ranorex.TabPage> tabList =
				repoItemInfo.CreateAdapters<Ranorex.TabPage>();
			
			string tabCount = tabList.Count.ToString();
			Report.Log(ReportLevel.Info,"tab count", "Tab count: " + tabCount);
			string tabName = "";
			// do whatever you want with each tab
			foreach (Ranorex.TabPage tab in tabList)
			{
				tab.EnsureVisible();
				tabName = tab.Element.GetAttributeValueText("AccessibleName");
				Report.Log(ReportLevel.Info,"tab name", "Tab Name: " + tabName);
				tabName = "";
			}
		}
These xpaths return all opened browser tabs:
IE:
/form[@class='IEFrame']//container/tabpagelist/tabpage[@accessiblerole='PageTab']
FF:
/form[@class='MozillaWindowClass']/toolbar[@accessiblename='Browser tabs']/tabpagelist/tabpage
Chrome:
/form[@class='Chrome_WidgetWin_1']//container/tabpagelist/tabpage
In a theory, you can use generic xpath like this:
/form[@class=$className]//tabpagelist/tabpage
Where $className is a variable, which makes the xpath ready for multiple browsers. However, the search for tabs could be quite slow for such simplified xpath.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Martin
Posts: 152
Joined: Fri Aug 15, 2014 12:24 pm

Re: How to get tab index using ranorex

Post by Martin » Fri May 27, 2016 9:31 am

Simplified full quick code for IE:
public void TabInfo()
        {
			var BrowserTabs = Host.Local.Find<TabPage>(@"/form[@title~'Internet Explorer$']//container[@class='TabBandClass']/?/?/tabpagelist[@accessiblename='Tab Row']/tabpage");
        	
			foreach (var tab in BrowserTabs)
			{
				string Index = tab.Element.GetAttributeValueText("Index");
				string Title = tab.Element.GetAttributeValueText("Title");
				string Selected = tab.Element.GetAttributeValueText("Selected");
				
				Report.Info("Index: " + Index + " Title: " + Title + " Selected: " + Selected);
			}
        }

AnithaKarthik
Posts: 3
Joined: Mon May 09, 2016 10:20 pm

Re: How to get tab index using ranorex

Post by AnithaKarthik » Mon Jun 13, 2016 1:37 pm

Thank you very much for both of your help. This is something , will help me to solve my issue. I will update if i had any roadblock while working on this.

vlau
Posts: 1
Joined: Mon Jun 13, 2016 1:40 pm

Re: How to get tab index in the mobile app?

Post by vlau » Thu Jun 16, 2016 4:24 pm

Hi, what command do i need to do for ranorex read the tab that I want it to click on?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to get tab index using ranorex

Post by Support Team » Fri Jun 17, 2016 1:28 pm

Hello valu,

Unfortunately, I'm not exactly sure what you want to do. Would you mind explaining your issue in more detail and upload a Ranorex Snapshot file in order to make the issue more understandable?
Thank you.

Regards,
Bernhard
.
Image