Selenium IDE:Opening in new tab and shift focus to

2019-01-24 10:36发布

i have stuck in one point in selenium ide

the scenario is like this

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

now from that point on-wards we have to shift our focus to that new tab because rest of the testing will be done on that new tab.

The code i have written is given below

     <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>

This code is working correctly upto clicking the sub menu from the dropdown after that it is not working and a error is showing in the log

so when ever i am trying to run that test case it is showing error

[warn] Link has target '_blank', which is not supported in Selenium! Randomizing target to be: selenium_blank84419

can any one please help me to write the code properly

9条回答
劫难
2楼-- · 2019-01-24 11:06

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>
查看更多
Melony?
3楼-- · 2019-01-24 11:07

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

查看更多
冷血范
4楼-- · 2019-01-24 11:11
<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

查看更多
登录 后发表回答