
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Click Allow on Show Notifications Popup Using Selenium WebDriver
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.
Syntax
ChromeOptions p = new ChromeOptions(); p.addArguments("--disable-notifications");
Let us try to handle the below notification on a page.
Example
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(); } }
Advertisements