Getting "org.openqa.selenium.NoSuchWindowException: no such window" exception in selenium

804 views
Skip to first unread message

suhali rattan

unread,
May 16, 2019, 1:31:54 PM5/16/19
to Selenium Users
Getting "org.openqa.selenium.NoSuchWindowException: no such window" exception in selenium while trying to swith to "childwindow" (multiple window handling concept).

CODE:
public class WindowHandling {

WebDriver driver;

public void invokeBrowser() {
try {
System.setProperty("webdriver.chrome.driver",
"D:\\Selenium Practice\\Suhali\\chromedriver_win32\\new chromedriver\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
driver.get(URL);
String parentwindow = driver.getWindowHandle();
System.out.println("parent window handle is:" + parentwindow);
driver.switchTo().frame("iframeResult");
driver.findElement(By.xpath("/html/body/button")).click();
String childwindow = driver.getWindowHandles().toArray()[1].toString();
System.out.println("child window handle is:" + childwindow);
driver.switchTo().window("childwindow");
System.out.println("title of the child window:" + driver.getTitle());
driver.close();
driver.switchTo().window(parentwindow);
System.out.println("title of the parent window:" + driver.getTitle());
driver.quit();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

public static void main(String[] args) {
WindowHandling wh = new WindowHandling();
wh.invokeBrowser();

}

}

using chromedriver version :74.0.3729.6
browser: Google chrome ver:  74.0.3729.157
O.S : Windows 10

Nagaraju Pogaku

unread,
May 16, 2019, 1:35:19 PM5/16/19
to seleniu...@googlegroups.com
Please remove " " for child window , you don't need to send it to window() with "" as your already storing it in string ..

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/d87a3da5-ee6d-4b98-ae37-6d1c68f4e8f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nagaraju Pogaku

unread,
May 16, 2019, 1:36:58 PM5/16/19
to seleniu...@googlegroups.com
try this driver.swith().window(childwindow) instead of driver.switch().window("childwindow")

On Thu, 16 May 2019, 23:01 suhali rattan, <suhali....@gmail.com> wrote:
--
Reply all
Reply to author
Forward
0 new messages