- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to handle chrome notification in Selenium?
We can handle Chrome notification in Selenium webdriver. These are generally known as the web push notifications and can be handled with the help of the ChromeOptions class. The below image shows a notification from the browser Chrome −
We have to create an object of this ChromeOptions class and apply the addArguments method on it. The parameter --disable-notifications is passed as a parameter to this method. Finally, this information is sent to the ChromeDriver.
Syntax
ChromeOptions o = new ChromeOptions(); o.addArguments("--disable-notifications");
Example
import org.openqa.selenium.By; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.WebDriver; public class NotificationChrome { public static void main(String[] args) throws IOException { //object of ChromeOptions ChromeOptions o = new ChromeOptions(); //set browser options o.addArguments("--disable-notifications"); System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); // pass browser option to webdriver WebDriver driver = new ChromeDriver(o); //implicit wait driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //URL launch driver.get("https://www.justdial.com/Bangalore/Bakeries"); } }
Output
Advertisements