- bhaskerActive particpant
- Posts : 18
Join date : 2012-06-11
HOW TO HANDLE LOOKUP(NEW WINDOW ) IN SELENIUM
Tue Jul 17, 2012 7:06 pm
HI,
I got a issue whille selecting an element from lookup (new window).I tried to the window title but unable to retrieve the window tile(using get window handls method)
I got a issue whille selecting an element from lookup (new window).I tried to the window title but unable to retrieve the window tile(using get window handls method)
- PonAruna
- Posts : 5
Join date : 2012-07-06
Re: HOW TO HANDLE LOOKUP(NEW WINDOW ) IN SELENIUM
Wed Jul 18, 2012 1:29 am
try
dr1.switchTo().window("popupwindow");
("popupwindow" is the window name)
or
for (String handle : dr1.getWindowHandles()) {
dr1.switchTo().window(handle);
}
dr1.switchTo().window("popupwindow");
("popupwindow" is the window name)
or
for (String handle : dr1.getWindowHandles()) {
dr1.switchTo().window(handle);
}
- bhaskerActive particpant
- Posts : 18
Join date : 2012-06-11
Re: HOW TO HANDLE LOOKUP(NEW WINDOW ) IN SELENIUM
Wed Jul 18, 2012 11:39 am
i tried in both ways but iam unable to switch to new window .is there any other method other these two
- PonAruna
- Posts : 5
Join date : 2012-07-06
Re: HOW TO HANDLE LOOKUP(NEW WINDOW ) IN SELENIUM
Wed Jul 18, 2012 9:17 pm
Hi
I believe you are trying this in either Selenium RC or webdriver
because either of this should work
I think you should try with some other example than with the one you are trying currently
give a try
import junit.framework.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class PopupWindow {
public static void main(String[] args){
WebDriver dr1=new FirefoxDriver();
dr1.get("http://book.theautomatedtester.co.uk");
WebElement linkChapter1=dr1.findElement(By.linkText("Chapter1"));
linkChapter1.click();
System.out.println(dr1.getTitle());
WebElement multipleWindowLink = dr1.findElement(By.xpath(".//*[@id='multiplewindow']"));
multipleWindowLink.click();
// Accessing the window by window Name
http://dr1.switchTo().window("popupwindow");
// alternate method to access the popup window if the window name is not known
for (String handle : dr1.getWindowHandles()) {
dr1.switchTo().window(handle);
}
Assert.assertEquals(dr1.findElement(By.xpath("//*[@id='popuptext']")).getText(), "Text within the pop up window");
WebElement popupWindowClose = dr1.findElement(By.xpath("//*[@id='closepopup']"));
popupWindowClose.click();
for (String handle : dr1.getWindowHandles()) {
dr1.switchTo().window(handle);
}
System.out.println(dr1.getTitle());
dr1.quit();
}
}
I believe you are trying this in either Selenium RC or webdriver
because either of this should work
I think you should try with some other example than with the one you are trying currently
give a try
import junit.framework.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class PopupWindow {
public static void main(String[] args){
WebDriver dr1=new FirefoxDriver();
dr1.get("http://book.theautomatedtester.co.uk");
WebElement linkChapter1=dr1.findElement(By.linkText("Chapter1"));
linkChapter1.click();
System.out.println(dr1.getTitle());
WebElement multipleWindowLink = dr1.findElement(By.xpath(".//*[@id='multiplewindow']"));
multipleWindowLink.click();
// Accessing the window by window Name
http://dr1.switchTo().window("popupwindow");
// alternate method to access the popup window if the window name is not known
for (String handle : dr1.getWindowHandles()) {
dr1.switchTo().window(handle);
}
Assert.assertEquals(dr1.findElement(By.xpath("//*[@id='popuptext']")).getText(), "Text within the pop up window");
WebElement popupWindowClose = dr1.findElement(By.xpath("//*[@id='closepopup']"));
popupWindowClose.click();
for (String handle : dr1.getWindowHandles()) {
dr1.switchTo().window(handle);
}
System.out.println(dr1.getTitle());
dr1.quit();
}
}
- popshaAmateur
- Posts : 60
Join date : 2012-04-14
Re: HOW TO HANDLE LOOKUP(NEW WINDOW ) IN SELENIUM
Thu Jul 19, 2012 11:13 am
hope viewing this link would find a perfect solution for you.
https://seleniumforum.forumotion.net/t1298-how-to-switch-window-in-webdriver
https://seleniumforum.forumotion.net/t1298-how-to-switch-window-in-webdriver
Permissions in this forum:
You cannot reply to topics in this forum
|
|