How can I resolve this error while using getWindowHandles() method: org.openqa.selenium.NoSuchWindowException ?

0 votes

How can I resolve this error while using getWindowHandles() method: org.openqa.selenium.NoSuchWindowException ?

Jul 31 in Selenium by Kabir
18 views

1 answer to this question.

0 votes

Hi Kabir, this type of error occurs when WebDriver tries to switch to an invalid window or to a window which doesn't exists. You can use try and catch to catch the exception in the following way:

for (String handle : driver.getWindowHandles()) {
  try {
    driver.switchTo().window(handle);
  } catch (NoSuchWindowException e) {
    System.out.println(“An exceptional case”);
  }
}
answered Jul 31 by Abha
• 20,110 points

Related Questions In Selenium

0 votes
1 answer

How can I download the *.jar file from http:// seleniumhq.org using selenium WebDriver?

For Selenium Standalone Server use this: profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/java-archive"); and ...READ MORE

answered Apr 9, 2018 in Selenium by Martin
• 4,220 points
414 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How can I implement Selenium using C#?

Reference https://www.seleniumhq.org/docs/03_webdriver.jsp#the-5-minute-getting-started-guide using OpenQA.Selenium.Firefox; using OpenQA.Selenium; class GoogleSuggest { ...READ MORE

answered Apr 9, 2018 in Selenium by Neville
40 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,070 points
441 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
791 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
433 views
0 votes
1 answer

How can I verify Error Message on a webpage using Selenium Webdriver?

Hey Hansraj, to verify an error message ...READ MORE

answered Jul 18 in Selenium by Abha
• 20,110 points
38 views
0 votes
1 answer