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 w
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.
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.
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
Simply use this code.
public void newtab(){
System.setProperty("webdriver.chrome.driver", "E:\\eclipse\\chromeDriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.w3schools.com/tags/att_a_target.asp");
//I have provided a sample link. Make sure that you have provided the correct link in the above line.
driver.findElement(By.className("tryitbtn")).click();
new Actions(driver).sendKeys(driver.findElement(By.tagName("html")), Keys.CONTROL).sendKeys(driver.findElement(By.tagName("html")), Keys.NUMPAD2).build().perform();
// In keyboard we will press
//ctrl+1 for 1st tab
//ctrl+2 for 2nd tab
//ctrl+3 for 3rd tab.
//Same action is written in the above code.
}
hi try this one ..
Set<String> winSet = driver.getWindowHandles();
List<String> winList = new ArrayList<String>(winSet);
String newTab = winList.get(winList.size() - 1);
System.out.println("winList: "+winList.size());
//driver.close(); // close the original tab
driver.switchTo().window(newTab);
Here are the steps I took for Selenium IDE:
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 ||
It worked for me.
[info] Executing: |storeEval | this.browserbot.findElement('link=Pastanet').href | Link_PastaNet |
[info] Executing: |openWindow | ${Link_PastaNet} | MyWindows |