How to get tab index using ranorex
-
- Posts: 3
- Joined: Mon May 09, 2016 10:20 pm
How to get tab index using ranorex
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
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...
These xpaths return all opened browser tabs:
IE:
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 = "";
}
}
IE:
FF:/form[@class='IEFrame']//container/tabpagelist/tabpage[@accessiblerole='PageTab']
Chrome:/form[@class='MozillaWindowClass']/toolbar[@accessiblename='Browser tabs']/tabpagelist/tabpage
In a theory, you can use generic xpath like this:/form[@class='Chrome_WidgetWin_1']//container/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./form[@class=$className]//tabpagelist/tabpage
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
Re: How to get tab index using ranorex
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); } }
-
- Posts: 3
- Joined: Mon May 09, 2016 10:20 pm
Re: How to get tab index using ranorex
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?
Hi, what command do i need to do for ranorex read the tab that I want it to click on?
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: How to get tab index using ranorex
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
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