Selenium IDE:Opening in new tab and shift focus to new tab not working

此生再无相见时 提交于 2019-11-29 04:19:04
John

The following code works for me:

<tr>
    <td>storeEval</td>
    <td>selenium.getAllWindowNames()[1]</td>
    <td>windowName</td>
</tr>
<tr>
    <td>getEval</td>
    <td>this.doEcho("array length: "+selenium.getAllWindowNames().length);this.doEcho("Available window names: "+selenium.getAllWindowNames());this.doEcho("Selecting window: "+storedVars['windowName']);</td>
    <td></td>
</tr>
<tr>
    <td>selectWindow</td>
    <td>${windowName}</td>
    <td></td>
</tr>

I hope it will help others who face a similar type of problem

use selectPopUp, but not storeEval and selectWindow, both of them are too complicated.

selectPopUp:

  • Arguments: windowID - an identifier for the popup window, which can take on a number of different meanings

  • Simplifies the process of selecting a popup window (and does not offer functionality beyond what selectWindow() already provides).

    • If windowID is either not specified, or specified as "null", the first non-top window is selected. The top window is the one that would be selected by selectWindow() without providing a windowID . This should not be used when more than one popup window is in play.
    • Otherwise, the window will be looked up considering windowID as the following in order: 1) the "name" of the window, as specified to window.open(); 2) a javascript variable which is a reference to a window; and 3) the title of the window. This is the same ordered lookup performed by selectWindow .

The code below ( selenium script, I copied from the selenium IDE ) indicates the action of:

1.click a 'edit' link

2.wait for 2 seconds ( waiting for the new window opened)

3.focus on the new window

<tr>
    <td>click</td>
    <td>link=edit</td>
    <td></td>
</tr>
<tr>
    <td>pause</td>
    <td>2000</td>
    <td></td>
</tr>
<tr>
    <td>selectPopUp</td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td>selectWindow</td>
    <td>http://10.0.1.101/magma/dev/fuelcost/</td>
    <td></td>
</tr>

Replace <td>http://10.0.1.101/magma/dev/fuelcost/</td> with window ID or window title or window name

Try with option selectWindow() Just provide the window title name withing (). For Ex: Window Title is Testing, then command : selectWindow title : Testing

To know the title of the newly opened window follow the steps: Go to the new window Right click->view page source Press ctrl+F. Type title and serch. You will get the title of the new window

I hope this helps someone out there! It worked well for me. You do still get the warning in the log, but the test works.

Please add waitForPopUp and selectPopUp event after clicking the new tab event. It's worked for me.

Kati Holasz

I am using the following and it works for me, hope it helps! :)

storeEval | this.browserbot.findElement('link=link name').href |    myUrl | 
open | ${myUrl}

As an alternative, it's possible to remove the target attribute from the link before clicking it. Here's the code to remove all target attributes from all links on the current page:

<tr>
    <td>runScript</td>
    <td>Array.from(document.links).forEach(function(link){link.removeAttribute('target')})</td>
    <td></td>
</tr>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!