Page 1 of 1
How to get tab index using ranorex
Posted: Thu May 26, 2016 6:47 pm
by AnithaKarthik
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?
Re: How to get tab index using ranorex
Posted: Fri May 27, 2016 9:10 am
by odklizec
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.
Re: How to get tab index using ranorex
Posted: Fri May 27, 2016 9:31 am
by Martin
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);
}
}
Re: How to get tab index using ranorex
Posted: Mon Jun 13, 2016 1:37 pm
by AnithaKarthik
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.
Re: How to get tab index in the mobile app?
Posted: Thu Jun 16, 2016 4:24 pm
by vlau
Hi, what command do i need to do for ranorex read the tab that I want it to click on?
Re: How to get tab index using ranorex
Posted: Fri Jun 17, 2016 1:28 pm
by Support Team
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