1
ChromeOptions options = new ChromeOptions();
driver.Navigate().GoToUrl("https://api.whatsapp.com/send/?phone=%2B0000000000000&text=I%27m+interested+in+your+car+for+sale&type=phone_number&app_absent=0");
Thread.Sleep(5000);
driver.SwitchTo().Alert().Dismiss();

I want to dismiss WhatsApp alert, that asking me to open whatsapp application. as well as i am getting exeption that OpenQA.Selenium.NoAlertPresentException: no such alert (Session info: chrome=109.0.5414.120) The picture below shows my problem.

enter image description here

I want to dismiss that notification so that the URL will take me to the contact which i want to message

Waseem
  • 23
  • 4
  • Are you getting an exception message, or is nothing happening at all? – Greg Burghardt Jan 27 '23 at 21:52
  • it's giving an exception message like ```OpenQA.Selenium.NoAlertPresentException: 'no such alert (Session info: chrome=109.0.5414.120)``` – Waseem Jan 28 '23 at 02:02
  • `Alert().Dismiss()` is for JS alerts... I'm pretty sure this is a browser-specific alert and does not qualify. Selenium will not work on any browser specific UI elements. You can try sendkeys but I don't think that will work either. You will likely have to use a different Windows UI library or create a profile where that URL is already accepted and load it using Selenium at the start of the test. – JeffC Jan 28 '23 at 07:17
  • @JeffC can you help me with this please ? – Waseem Jan 28 '23 at 10:11

1 Answers1

1

I think this is the same problem as this so following this answer instead of simulate clicking just replace api.whatsapp.com in the URL with web.whatsapp.com.

e.g. (referring to your case)

String url = "https://api.whatsapp.com/send/?phone=%2B0000000000000&text=I%27m+interested+in+your+car+for+sale&type=phone_number&app_absent=0";
url = url.Replace("api.whatsapp.com", "web.whatsapp.com");
driver.Navigate().GoToUrl(url);

If you need to use it as a part of some e2e test then you can read the URL from the browser using url = driver.Url;, do replacement and again navigate to the new URL.

// doing some stuff with driver what causes navigation to WhatsApp
String url = driver.Url;
url = url.Replace("api.whatsapp.com", "web.whatsapp.com");
driver.Navigate().GoToUrl(url);

Thread.Sleep(5000); is no needed. Additionally, I can elaborate, that Thread.Sleep(5000); is generally considered as a bad practice. It is explained in details here.