Error while closing New Tab window | Selenium Forum
M
Posted on 22/11/2016
Hi ,

I am implementing POM with page factory in my project
and i am facing an issue

there is a page in the application inside this page "folder" link exist when i click on this a pop up gets open
i have to search a folder and select this (entering foldername ,select radio button ,click on go button)
which is i am able to do but when i click on Go button after fill all the data for this pop up
this pop up get closed and selected data display on the main page but after this my next command is not getting executed like fill the value in the next fileds.

i am calling below method in the my test page


public void TabHandles() throws Throwable {

String currentWindowHandle = driver.getWindowHandle();

//Get the list of all window handles
ArrayList<String> windowHandles = new ArrayList<String>(driver.getWindowHandles());

for (String window:windowHandles){

//if it contains the current window we want to eliminate that from switchTo();
if (window != currentWindowHandle)
{
//Now switchTo new Tab.
driver.switchTo().window(window);
//Do whatever you want to do here.
//driver.close();


driver.switchTo().defaultContent();
}


}



Logic in the TestPage---

public ProfilePage CompleteUccForm() throws Throwable {

test.log(LogStatus.INFO, "Cliking in the UCC Tab");
//upload.click();


ucc.click();

folder.click();


//newttab();

tabHandles();

foldertext.sendKeys("Applesamsung");
foldergo.click();
folderradio.click();
folderselect.click();

// maintabttab();

realestatecheck.click();
contactname.sendKeys("deepak");
relation.sendKeys("Lessee/Lessor");


and my test case is getting failed. with the Below error ---

FAILED: CompleteUccForm-
org.openqa.selenium.NoSuchWindowException: Window not found. The browser window may have been closed.
Command duration or timeout: 31 milliseconds
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52'
System info: host: 'DS-E0699598D816', ip: '10.97.222.20', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_66'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=37.0.2, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 6ca9a623-ea39-4c16-a7dd-e1b3f80afd04
*** Element info: {Using=xpath, value=//*[@id='ctrlLien_lienHeadercontrol_chkFixture']}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)


My Query :after click on Go button pop up getting closed while i did not call the driver.closed
and i am not able to fill the data next to it as due to getting error.

Pls provide the solution--


thanks
deepak

M
Replied on 23/11/2016

hi ,

PFA SCREEN SHOT error and Pop Up

Responsive image

M
Replied on 23/11/2016

i look into it. give me a day or 2.


M
Replied on 24/11/2016

have you tried switching to main window.

i could not understand your code.


M
Replied on 25/11/2016

Yes I am coming to main window after fill the data from the main window as I already explained Above..
if you did not understand my code please tell me the code how to execute code after fill the data ..from pop up window and back to main window and resume working on main window.

I think it is more easy to you and me also



having said that as code regarding --POP up provided by you for action on Pop Up is not working here. this is only for closing the pop up only

so give me the code which you think should used

Reply ASAP


M
Replied on 25/11/2016

[code:1p1fkckf]driver.get("your website");

// Store parent window name

String parent_window = driver.getWindowHandle();

// print parent window ID
System.out.println(parent_window);

// Get list & Size of all open windows
List<String> windows = new ArrayList<String>(driver.getWindowHandles());

System.out.println(windows.size());
System.out.println(windows);
System.out.println(driver.getTitle());

for (String child_window : windows) {
if (!parent_window.equals(child_window)) {
//switching to pop up
driver.switchTo().window(child_window);
System.out.println(driver.getTitle());
} else {
System.out.println(driver.getTitle());
}
}
System.out.println(driver.getTitle());
driver.close(); // closing the pop up. deepak you don't need to do this

driver.switchTo().window(parent_window); //returning to main window.
System.out.println(driver.getTitle());



[/code:1p1fkckf]


M
Replied on 30/11/2016

Hi When I am using ur code focus is going to move from pop up to main window whithout fill the data of the Pop Window
and this pop remain open in the back of the Main window


OutPut is fail with the below message


{a3763f14-b974-49ab-96a2-4e4dbbdce40e}
2
[{a3763f14-b974-49ab-96a2-4e4dbbdce40e}, {56bf93e4-a0c1-4289-a188-bc133aa78e9a}]
iLien
iLien
iLien Online - Folder Name Lookup
iLien Online - Folder Name Lookup
iLien
FAILED: CompleteUccForm
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//*[@id='txtNameLookup']"}
Command duration or timeout: 50.11 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html



Method -2

when I am commenting

//driver.switchTo().window(parent_window); //returning to main window.

able to fill the data of the POP up also getting error --


org.openqa.selenium.NoSuchWindowException: Window not found. The browser window may have been closed.
Command duration or timeout: 16 milliseconds
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52'
System info: host: 'DS-E0699598D816', ip: '10.97.222.20', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_66'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=37.0.2, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: a9dd2842-6c12-4ef7-914c-b49737e18cdd
*** Element info: {Using=xpath, value=//*[contains(@name,'btnSelect')]}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)


M
Replied on 30/11/2016

give me the code you're using.


M
Replied on 30/11/2016

hi pfa


M
Replied on 30/11/2016

do it like this.

Responsive image

M
Replied on 30/11/2016

HI STILL SME ISSUE

pfa screen shot

Responsive image

M
Replied on 30/11/2016

still same issue ..unable to proceed with main window and test case getting failed