How to get a window Title and use that to switch to that new Tab?

This is probably easy as heck but I been trying for too long and couldn’t get the desired result.

I’m basically trying to work with a dynamic page that can have different windowTitle depends on certain scenarios. So basically I’m writing bunch of variables to get this test to run properly.

This is my problem:
I am trying to switchToWindow title after clicking on a button on current tab… but it’s not simple because the second tab is dynamic so I need to getWindowTitle first and then Switch to it. But my code below gets the CURRENT title, hence it’s staying on that tab.

This is what I got:
String Title = WebUI.getWindowTitle()
WebUI.switchToWindowTitle(Title)

I even tried something i thought it would work… like a partial windowTitle…
WebUI.switchToWindowTitle('partial title '.trim())

Ehh… I figured it out. It didn’t work before for some reason… I can’t delete the post but maybe it will help someone else…
I just added the switch to the first index and it switched to the 1st tab that opened.

I just added:
WebUI.switchToWindowIndex(1)
String Title = WebUI.getWindowTitle()