Gain control of tabs for Xpath

Hi There

Currently working on a platform which often opens up a new tab. I have no problem being able to interact on the new tab (tab 2) by using the following script:

@CustomScriptAction(
)

def customScript() {
   switchToNextWindow()
}

However, on the new tab, once I’ve done processing information on that tab, I click an element that closes the 2nd tab (an actual web element on the tab). I cannot get control of the original tab (tab 1), even using the following script.

@CustomScriptAction(
)

def customScript() {
   switchToPrevWindow()
}

Please assist

Thank you

Paulo

Hi @paulo_scholle is it necessary to close the tab by clicking on the web element?
Can you switch to the previous tab before closing the current tab and then close it using keystrokes?

switch-to-tab-keystrokes.zip (896 Bytes)

Here is one more way you can do it:

After you open the browser, use Constant value action to get the handle of the current window:

${driver().getWindowHandle()}

After you close the second tab, switch to the first tab using the handle in a custom action:

@CustomScriptAction(
input = ['window_name']
)

def customScript() {
   window("${window_name}")
}

switch-to-tab-sample.zip (957 Bytes)

Here is a sample script

Hope it helps!:slightly_smiling_face:

1 Like

Hi,

I am trying to open a form from one online website. The form is being opened in a new tab of the same browser and when I try to fill the form fields through a mouse click and keyboard keystrokes bot task failing to find the xpath. Can anyone help me with this?

Thank you.

Best Regards,
Lakshminarayana Golla

1 Like

Hi @LG00560059 in order to use Xpaths in a new tab, you need to switch to it using custom actions. You can see examples of actions you can use in the posts above.

Thank you @ashapkina for your help.

1 Like

Hi, I have a continuing question, my browser application will automatically open a new tab after logging in on the first tab. However, I am required to open the third tab to first change my download preference, after which I have to close that third tab and navigate to the “second tab” instead to continue my processes. Using the above script (grab window handle and the switching script), I ended up going to the very first tab, instead of the second tab. Could you kindly suggest modifications to the script to allow me to specifically select the second tab instead?