Q:

how to handle browser pop up(you might lose the data, are you sure you want to continue?',  with two options: Leave the page Stay on page)

My scenario

i am working on page 1
i have to switch to page 2
but the pop up is coming, with text
you might lose the data, are you sure you want to continue?,  
with two options:

Leave the page
Stay on page

i have to choose "leave the page" option
but how to handle this pop up, 
(note :-i) this is not an alert, so switch to alert is not working 
ii) even (( JavascriptExecutor ) webDriver).executeScript( "window.close()" ); is not working )
then only i can switch to page 2
can someone please help on this 

A:

Although It doesn't  seems as an alert because alert.accept() or alert.dismiss() doesn't works.(as you haven't shared html) Just try the following code -
First switch on that alert -
Alert alert = driver.switchTo().alert();

and then change focus to  leave if your default focus is on Stay
alert.sendKeys(Keys.chord(Keys. TAB)); //By pressing TAB key in this way

and then click the button
alert.dismiss();

