Stark
Stark

Reputation: 481

Switching tab in Selenium IDE

How can I focus on a newly opened window in Selenium IDE?

I am clicking on a link and a new tab will open. However I am not able to shift the focus to the new window.

I have tried this other SO answer, but it still doesn't work.

Here is the code that I have tried:

<tr>
    <td>storeEval</td>
    <td>selenium.getAllWindowTitles()[0]</td>
    <td>windowName</td>
</tr>
<tr>
    <td>getEval</td>
    <td>this.doEcho(&quot;array length: &quot;+selenium.getAllWindowNames().length);this.doEcho(&quot;Available window names: &quot;+selenium.getAllWindowNames());this.doEcho(&quot;Selecting window: &quot;+storedVars['windowName']);this.doEcho(&quot;Available window Titles: &quot;+selenium.getAllWindowTitles());</td>
    <td></td>
</tr>
<tr>
    <td>echo</td>
    <td>${windowName}</td>
    <td></td>
</tr>
<tr>
    <td>selectWindow</td>
    <td>title=${windowName}</td>
    <td></td>
</tr>

This code is using the current tab instead of the new tab and in echo it is printing the title of current tab and hence focussing again on current tab. When I use 1 instead of 0 in the array parameter (selenium.getAllWindowTitles()[1]) in the first line, it is printing null.

I have also tried with names instead of titles but it still does not work.

Upvotes: 1

Views: 3404

Answers (2)

Uren You
Uren You

Reputation: 25

Did you try to add the command waitForPopUp before the selectWindow?

This is what my code looks like for my test case when I tried to make the selectWindow command work:

<tr>
    <td>click</td>
    <td>link=Named window by hyperlink</td>
    <td></td>
</tr>
<tr>
    <td>waitForPopUp</td>
    <td></td>
    <td>30000</td>
</tr>
<tr>
    <td>selectWindow</td>
    <td>name=namedWindowByHyperlink1</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>link=Named window by hyperlink</td>
    <td></td>
</tr>
<tr>
    <td>waitForPopUp</td>
    <td></td>
    <td>30000</td>
</tr>
<tr>
    <td>selectWindow</td>
    <td>name=namedWindowByHyperlink2</td>
    <td></td>
</tr>
<tr>
    <td>verifyText</td>
    <td>css=p</td>
    <td>Test was completed.</td>
</tr>

When I used this code, I could pass the test case when I tried to focus to new window.

Hope it could help you.

If you need, please try to use the tool, SideeX, the extended version of Selenium IDE. SideeX is now being used as the basis of 'The Next Generation' of Selenium IDE.

I have some new ideas about windows and frames problems in this tool to make the test case work.

Upvotes: 1

Klendathu
Klendathu

Reputation: 793

I had a similar issue, in a test environment, all the windows were basically assigned the same name. Whenever I tested a feature that opened a new tab, I just used

selectWindow new

and when I was done testing that page,

closeWindow to close that new tab, then

selectWindow with either NULL or no arguments to get back to the main window.

Upvotes: 0

Related Questions