StackPHPcRoW
StackPHPcRoW

Reputation: 61

Is it possible to disable all alerts() in page

i am using selenium and i want to disable all alerts() in webpage.

ExecuteScript("document.body.innerHTML = document.body.innerHTML.replace('alert(', '');");

I tried the above script, but don't have the behaviour that I want.

The code replace but the alert still fired!

Upvotes: 1

Views: 141

Answers (2)

Udbhav
Udbhav

Reputation: 212

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

Upvotes: 1

ProgrammingLlama
ProgrammingLlama

Reputation: 38777

I assume that this would work:

ExecuteScript("alert = function() { }");

It will replace the alert method with an empty function.

Upvotes: 2

Related Questions