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,320 points
29,890 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);

Hope this helps!

Join our Selenium online training here for more details!

Thanks!

answered Jun 20, 2018 by Samarpit
• 5,910 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 :)
+2 votes
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 Mar 1, 2020 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 30, 2020 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
• 28,140 points
7,241 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 30, 2018 in Selenium by Damon Salvatore
• 5,980 points
5,364 views
0 votes
1 answer

Handling calendar popup using Selenium WebDriver

You are selecting wrongly your elements in ...READ MORE

answered Apr 17, 2018 in Selenium by Shubham
• 13,490 points
4,481 views
+2 votes
3 answers

How can we handle authentication popup in Selenium WebDriver using Java

1) By passing user credentials in URL. String ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
29,083 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,500 points
13,686 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,149 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,910 points
7,228 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 3, 2020 in Selenium by Sri
• 3,190 points
7,880 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP