Handling new window using Selenium

0 votes

Below is the code:

driver.findElement(By.id("NewButton")).click();
//Thread.sleep(3000);
String new1 = driver.getWindowHandle();
driver.switchTo().window(new1);
driver.findElement(By.id("srcNewCode")).sendKeys("977343");
So, this was the error

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with id == srcNewCode (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 404 milliseconds.
Please Help????
Apr 2, 2018 in Selenium by code_ninja
• 5,750 points
1,089 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You are not switching to new window. For this save the original window
then get the window handle of the new window and switch to that.After new window work is done ,
close the to and switch to original window handle. Use below code for reference

String parentHandle = driver.getWindowHandle();
driver.findElement(By.xpath("//*[@id='someXpath']")).click();

for (String winHandle : driver.getWindowHandles()) {
    driver.switchTo().window(winHandle); // switch focus of WebDriver to the next found window handle
}

//code for on new window

driver.close(); // close newly opened window
driver.switchTo().window(parentHandle); // switching back to the original window
answered Apr 2, 2018 by DragonLord999
• 8,360 points

Related Questions In Selenium

0 votes
1 answer

Handling a popup window using selenium

This is a code I use when ...READ MORE

answered Aug 31, 2018 in Selenium by Meci Matt
• 9,400 points
71 views
0 votes
1 answer

I tried to open a new website when a new tab is opened using Selenium Webdriver

Try this code: ArrayList<String> tabs = new ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,030 points
479 views
0 votes
1 answer

Handling JavaScript Alert window in Selenium WebDriver

You should try using waits for alerts ...READ MORE

answered Apr 10, 2018 in Selenium by ghost
• 1,790 points
586 views
0 votes
1 answer

Handling calendar popup using Selenium WebDriver

You are selecting wrongly your elements in ...READ MORE

answered Apr 17, 2018 in Selenium by Shubham
• 12,270 points
965 views
0 votes
1 answer

Maximizing the browser window in Selenium WebDriver using C#

Check this first: http://code.google.com/p/selenium/issues/detail?id=174 You Can use the JavascriptExector as follows: public ...READ MORE

answered May 2, 2018 in Selenium by Samarpit
• 5,130 points
45 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,030 points
72 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
444 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
55 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.