-5

Handle alert

Do you want to leave this site?

I am using chrome 64 for selenium Java.

Getting Below Error:

rg.openqa.selenium.UnhandledAlertException: unexpected alert open: {Alert text : }
  (Session info: chrome=64.0.3253.3)

Error Screenshot

2 Answers2

1

Try to handle the Alert by doing something like this :

//Dismiss the alert
driver.switchTo().alert().dismiss();

//Accept the alert
driver.switchTo().alert().accept();

Have a look at this article for more information about alert handling in selenium.

BastianBuhrkall
  • 348
  • 1
  • 7
  • 18
  • Hi,already done with this code and getting error "alert is not present " – Kirtiman Singh Nov 09 '17 at 06:56
  • Check out the suggested duplicate. If that does not Help, please be more specific in your questioning and show us Some code. This may be a different question but we simply cant tell without knowing more – BastianBuhrkall Nov 09 '17 at 07:21
  • Scenario: When i am going out my Website, Getting Pop up as "Do you want to leave this site,changes you made may not be saved".. i tried with robot class also but it works sometime only.. – Kirtiman Singh Nov 09 '17 at 09:14
0

You can use alert interface for that

  Alert alert = driver.switchTo().alert();
  alert.accept();   //for accept
  alert.dismiss();//for dismiss
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36