Click Allow on Show Notifications popup using Selenium Webdriver

0 votes

I'm trying to login to Facebook. After a successful login, I get a browser popup:

Can I click Allow and proceed forward using selenium webdriver?

Jun 20, 2018 in Selenium by Martin
• 4,340 points
16,751 views
sorry no allow this code because i am using
Can you please be little more specific? Can't really understand what you're trying to say.
i am facing this issue on windows using python in selenium

Try this:

alert_obj = driver.switch_to.alert
alert_obj.accept()
@Omkar, have you tried the code that you have written coz its not working for me
Hey @Nischitha what error are you getting?

try the below one to allow/block the permission

1- allow, 2-block

Chrome-

ChromeOptions options=new ChromeOptions();
Map prefs=new HashMap();
prefs.put(“profile.default_content_setting_values.notifications”, 1);
options.setExperimentalOption(“prefs”,prefs);
ChromeDriver driver=new ChromeDriver(options);

Firefox-

WebDriver driver ;
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(“permissions.default.desktop-notification”, 1);
DesiredCapabilities capabilities=DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
driver = new FirefoxDriver(capabilities);
driver.get(“your Web site”);

If I just want to click on the "X" - to close this browser popup through selenium webdriver, then what method will be use to close this popup ?(if neither want to allow nor block, then how do I close it).

Hello @Surbhi,

The dismiss() alert class method is used to close the alert for handling alerts in Selenium. It operates by clicking on the “X” button in the prompt. This method is functional for all alert types: prompt, alert and confirmation dialogue box. The protractor web driver uses a void dismiss() command to cancel the alert.

driver.switchTo().alert().dismiss();

Hope it helps!!

Thank you!

3 answers to this question.

+1 vote

Create a instance of ChromeOptions class

ChromeOptions options = new ChromeOptions();

Then Add chrome switch to disable notification - "--disable-notifications"

options.addArguments("--disable-notifications");

After that set path for driver exe

System.setProperty("webdriver.chrome.driver","path/to/driver/exe");

and then pass ChromeOptions instance to ChromeDriver Constructor

WebDriver driver =new ChromeDriver(options);

answered Jun 20, 2018 by Samarpit
• 5,890 points
But the request is not to disable notifications. The request is to click "Allow".
@pinkninjatester, unfortunately there is no option to do that. Because the above subject is not treated as a browser popup, but infact it is treated as a browser notification.

Disabling this notification should hopefully solve your problem as the execution will continues without any hindrance. Let me know if anything otherwise happens :)
+1 vote
Try this:

Robot robot = new Robot();
robot.delay(5000);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_ENTER);

hope this will help you.
answered Feb 29 by anuj
Prefect! It worked for me. Thank you.
thanks  it worked for me also in chrome version 81
Thanks ...... it worked for me also in chrome version 86
Great! It worked for me as well.
0 votes
Same error is occurring for me, So please help me.
answered Aug 29 by anonymous
Hey, have you tried @Samarpit's and @anuj's solution?

Related Questions In Selenium

0 votes
1 answer

How to click on a hyperlink using Selenium WebDriver?

Hi Jonathan, you can use click() method in ...READ MORE

answered May 29, 2019 in Selenium by Abha
• 27,950 points
4,533 views
0 votes
1 answer

Double click a record in a grid using Selenium webdriver

Try Actions class to perform this Actions action ...READ MORE

answered Mar 29, 2018 in Selenium by Damon Salvatore
• 5,550 points
2,413 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,520 points
4,012 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,955 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,903 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
3,326 views
0 votes
1 answer

Wait until page loads before click() using Selenium Webdriver

Change the following guestlogin_button = wait.until(EC.visibility_of_element_located((By.id, ".ch4_loginGuestBtn"))) to guestlogin_button = ...READ MORE

answered Aug 8, 2018 in Selenium by Samarpit
• 5,890 points
2,676 views
0 votes
1 answer

Firefox browser not opening with given URL using Selenium Webdriver with Java

Download the latest selenium jar and replace ...READ MORE

answered Apr 30, 2018 in Selenium by Samarpit
• 5,890 points
4,865 views