tags:

views:

3692

answers:

5

I'm using Selenium and Firefox.

I have a link on a page (say linkA) that opens a new page in a new tab. The new tab is displayed when linkA is clicked. I then want to interact with the new page.

Here is my selenium script:

  • click linkA
  • pause 5000
  • selectWindow Title
  • click linkB (note: linkB is on the new page)

Selenium cannot identify the new tab. It reports:

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

Is there any way to tell Selenium to interact with the displayed tab?

+2  A: 

Did you try adding a windowFocus between selectWindow and click linkB?

Edit: selectWindow takes a Javascript windowID. Does your linkA specify a windowID for Selenium to access?

Here is the full first test page (t1.html), in the window.open call the 2nd parameter is 'WindowTest', this is the javascript windowID that selenium looks for.

<a href="javascript:void(0);" name="t1" 
   onclick="window.open('t2.html', 'WindowTest', 'width=450,height=600');">
 test
</a>

Here is the second test page (t2.html):

<a href="t1.html" name="t2">2test2</a>

Running your script ends up with the popup window on t1.html My script

click              link=test
pause              5000
selectWindow       WindowTest
windowFocus
click              link=2test2
s_hewitt
A: 

Hi

I am having the same problem as the original post. I looked at your solution but the trouble is as outlined the link opens in a new tab in the same window.(if it opens in a new window then the select window works) So when we use the selectwindow command the script fails as the new name is applied to this window only when the new tab is activated and I am not sure how to select this new tab.

Does anyone have a solution for this?

A: 

Here are the steps I took for Selenium IDE:

  1. find the link in question
  2. remove the attribute “target” from the link
  3. copy the href destination in a variable (myUrl)
  4. modify the link href->javascript:window.open(myUrl,’myWindow’)
  5. click on link
  6. select window ‘myWindow’

getEval | this.page().findElement(‘link=click here’).removeAttribute(‘target’)||

storeEval | this.page().findElement(‘link=click here’).href | myUrl

getEval | this.page().findElement(‘link=click here’).href=”javascript:window.open(‘${myUrl}’,'myWindow’)” ||

click | link=click here ||

pause | 1000 ||

selectWindow | name=myWindow ||

lericain59
A: 

lericain59's sent me in the right direction, though I had to make a few changes for it work with my version of selenium's IDE (I'm running 1.0.6). Also, for my purposes, I didn't need to verify so much that it opened in a separate window, only that it was opening the correct window.

Here's the script that worked for me.

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

this.page() didn't work. It seems to have been replaced with this.browserbot. Also, I just opened the page directly - it avoids a manual pause and has less steps.

bsegraves
A: 

how can i open a new tab in same window ... all the above and in other are good but ...still can't help in opening a new tab in Selenium RC. any help on this

Mayank