Aliz
Aliz

Reputation: 59

How to disable the "Are you sure you want to leave this page" alert?

I am using c # selenium webdriver. I want to turn off chrome warnings. For example, disable the are you sure to leave this page alert. None of the codes below worked. You can help with the explanatory code.

private void Form1_Load(object sender, EventArgs e)
{
    ChromeOptions options = new ChromeOptions();
    options.AddArgument("--disable-notifications");
    options.AddArguments("--disable-extensions"); // to disable extension
    options.AddArguments("--disable-notifications"); // to disable notification
    options.AddArguments("--disable-application-cache"); // to disable cache
    options.AddArgument("--safebrowsing-disable-download-protection");
    options.AddArgument("ignore-certificate-errors");
    options.AddArgument("--disable-popup-blocking");
    options.AddArgument("--disable-gpu");
    options.AddArgument("--incognito");
    options.AddUserProfilePreference("disable-popup-blocking", "true");
    driveri = new ChromeDriver(options); 
    driveri.Navigate().GoToUrl("http://web.com");

    IJavaScriptExecutor js = (IJavaScriptExecutor)driveri; 
    js.ExecuteScript("window.alert = function() {};");
}

Upvotes: 3

Views: 1743

Answers (1)

Aliz
Aliz

Reputation: 59

Hi I solved my problem with the Let Me Out named chrome extensions. Maybe it's what he needs. Below my sample code.

 ChromeOptions options = new ChromeOptions();
 options.AddArgument("--disable-notifications");
 options.AddExtensions(@"C:\Let-Me-Out_v1.3.crx");
 driveri = new ChromeDriver(options); 

Upvotes: 3

Related Questions