@@ -53,24 +53,34 @@ public WebDriver getDriver()
5353 return _driver ;
5454 }
5555
56+ public WebElement findTab (String tabText )
57+ {
58+ return elementCache ().findTab (tabText );
59+ }
60+
5661 public WebElement findPanelForTab (String tabText )
5762 {
58- return elementCache ().findTabPanel (tabText );
63+ return elementCache ().findTabPanel (elementCache (). findTab ( tabText ) );
5964 }
6065
6166 public WebElement selectTab (String tabText )
6267 {
6368 WebElement tab = elementCache ().findTab (tabText );
6469 getWrapper ().scrollIntoView (tab );
6570 tab .click ();
66- WebElement panel = findPanelForTab ( tabText );
71+ WebElement panel = elementCache (). findTabPanel ( tab );
6772 getWrapper ().shortWait ().until (ExpectedConditions .visibilityOf (panel ));
6873 return panel ;
6974 }
7075
76+ public WebElement findPanelForActiveTab ()
77+ {
78+ return elementCache ().findTabPanel (elementCache ().findSelectedTab ());
79+ }
80+
7181 public boolean isTabSelected (String tabText )
7282 {
73- return Boolean .valueOf (elementCache ().findTab (tabText ).getAttribute ("aria-selected" ));
83+ return Boolean .valueOf (elementCache ().findTab (tabText ).getDomAttribute ("aria-selected" ));
7484 }
7585
7686 public List <String > getTabText ()
@@ -80,6 +90,16 @@ public List<String> getTabText()
8090 .stream ().map (WebElement ::getText ).toList ();
8191 }
8292
93+ public String getSelectedTabText ()
94+ {
95+ return elementCache ().findSelectedTab ().getText ();
96+ }
97+
98+ public String getSelectedTabKey ()
99+ {
100+ return elementCache ().findSelectedTab ().getDomAttribute ("data-event-key" );
101+ }
102+
83103 @ Override
84104 protected ElementCache newElementCache ()
85105 {
@@ -102,6 +122,11 @@ public ElementCache()
102122 }
103123 }
104124
125+ protected WebElement findSelectedTab ()
126+ {
127+ return tabLoc .withAttribute ("aria-selected" , "true" ).findElement (this );
128+ }
129+
105130 List <WebElement > findAllTabs ()
106131 {
107132 if (tabs .isEmpty ())
@@ -125,25 +150,25 @@ WebElement findTab(String tabText)
125150 catch (NoSuchElementException ex )
126151 {
127152 throw new NoSuchElementException (String .format ("'%s' not among available tabs: %s" ,
128- tabText , getWrapper ().getTexts (findAllTabs ())), ex );
153+ tabText , getWrapper ().getTexts (findAllTabs ())), ex );
129154 }
130155 tabMap .put (tabText , tabEl );
131156 }
132157 return tabMap .get (tabText );
133158 }
134159
135160 // Tab panels can be updated and changed when flipping between tabs. Don't persist the panel element find it each time.
136- WebElement findTabPanel (String tabText )
161+ WebElement findTabPanel (WebElement tabElement )
137162 {
138- String panelId = findTab ( tabText ). getAttribute ("aria-controls" );
163+ String panelId = tabElement . getDomAttribute ("aria-controls" );
139164 WebElement panelEl ;
140165 try
141166 {
142167 panelEl = Locator .id (panelId ).findElement (tabContent );
143168 }
144169 catch (NoSuchElementException ex )
145170 {
146- throw new NoSuchElementException ("Panel not found for tab : " + tabText , ex );
171+ throw new NoSuchElementException ("Panel not found for tab : " + tabElement . getText () , ex );
147172 }
148173
149174 return panelEl ;
0 commit comments