We can click Allow on show notification pop-up in Selenium webdriver.These are messages from the website and often called as web push notification.This can be handled with the browser settings.
This is done with the help of the ChromeOptions class. We shall create an object of it and apply the addArguments method on it. Then pass --disable-notifications as a parameter to the method.
Finally, this information should be sent to the driver object.
ChromeOptions p = new ChromeOptions(); p.addArguments("--disable-notifications");
Let us try to handle the below notification on a page.
Code Implementation.
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import java.util.concurrent.TimeUnit; public class BrowserNotification{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe"); //ChromeOptions object ChromeOptions op = new ChromeOptions(); //disable notification parameter op.addArguments("--disable-notifications"); // configure options parameter to Chrome driver WebDriver driver = new ChromeDriver(op); driver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS); driver.get("https://www.redbus.in/"); driver.quit(); } }