8

我在 selenium ide 中停留了一点

场景是这样的

Login-----

go to dashboard page---------

mouse over any menu on the top navigational bar----

on mouseover sub menu will appear as drop down--

now click any link from the drop down --

after clicking link will open in new tab

现在从那时起,我们必须将注意力转移到那个新选项卡上,因为其余的测试将在那个新选项卡上完成。

我写的代码如下

     <tr>
    <td>open</td>
    <td>/magma/dev/</td>
    <td></td>
</tr>
<tr>
    <td>type</td>
    <td>name=user_id</td>
    <td>abcd</td>
</tr>
<tr>
    <td>type</td>
    <td>name=pass</td>
    <td>1234</td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>id=btnLogin</td>
    <td></td>
</tr>
<tr>
    <td>verifyTextPresent</td>
    <td>Costing List</td>
    <td></td>
</tr>
<tr>
    <td>verifyTextPresent</td>
    <td>Fuel</td>
    <td></td>
</tr>
<tr>
    <td>mouseOver</td>
    <td>//div[@id='smoothmenu1']/ul/li[3]</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>link=Fuel Cost</td>
    <td></td>
</tr>
<tr>
    <td>selectWindow</td>
    <td>http://10.0.1.101/magma/dev/fuelcost/</td>
    <td></td>
</tr>
<tr>
    <td>verifyTextPresent</td>
    <td>Manage Fuel Cost</td>
    <td></td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>link=Logout</td>
    <td></td>
</tr>

此代码正常工作,直到从下拉菜单中单击子菜单,之后它不起作用并且日志中显示错误

因此,当我尝试运行该测试用例时,它会显示错误

[警告] 链接有目标“_blank”,Selenium 不支持!随机化目标为:selenium_blank84419

谁能帮我正确编写代码

4

9 回答 9

10

以下代码适用于我:

<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

于 2012-12-03T09:07:20.223 回答
2

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>
于 2013-01-10T09:53:59.460 回答
1
<tr>
    <td>selectWindow</td>
    <td>http://10.0.1.101/magma/dev/fuelcost/</td>
    <td></td>
</tr>

替换<td>http://10.0.1.101/magma/dev/fuelcost/</td>window IDorwindow titlewindow name

于 2012-07-07T07:20:03.317 回答
1

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

于 2013-08-08T13:27:55.333 回答
1

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.

Selenium IDE workaround for _blank error

于 2015-04-01T16:24:30.110 回答
1

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

于 2017-01-24T09:47:01.080 回答
0

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

storeEval | this.browserbot.findElement('link=link name').href |    myUrl | 
open | ${myUrl}
于 2016-03-20T10:53:51.650 回答
0

I use storeAttribute incombination with open.

Link: http://www.seleniumwiki.com/software-testing/how-to-solve-the-link-has-target-_blank-which-is-not-supported-in-selenium/

I use it like this:

enter image description here

于 2017-05-11T14:39:34.643 回答
0

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>
于 2017-05-16T21:57:11.660 回答