I'm trying to login to Facebook. After a successful login, I get a browser popup:
How with the webdriver can I click Allow and proceed forward?
I'm trying to login to Facebook. After a successful login, I get a browser popup:
How with the webdriver can I click Allow and proceed forward?
Please Follow below steps :
Step 1:
//Create a instance of ChromeOptions class
ChromeOptions options = new ChromeOptions();
Step 2:
//Add chrome switch to disable notification - "--disable-notifications"
options.addArguments("--disable-notifications");
Step 3:
//Set path for driver exe
System.setProperty("webdriver.chrome.driver","path/to/driver/exe");
Step 4 :
//Pass ChromeOptions instance to ChromeDriver Constructor
WebDriver driver =new ChromeDriver(options);
This not an alert box, so you can't handle it using Alert
, this is a chrome browser notification, To Switch off this browser notification you need to create chrome preference map with chrome option as below :-
//Create prefs map to store all preferences Map prefs = new HashMap(); //Put this into prefs map to switch off browser notification prefs.put("profile.default_content_setting_values.notifications", 2); //Create chrome options to set this prefs ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", prefs); //Now initialize chrome driver with chrome options which will switch off this browser notification on the chrome browser WebDriver driver = new ChromeDriver(options); //Now do your further steps
Hope it helps..:)
import unittest from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions from selenium.webdriver.chrome.options import Options from selenium import webdriver import time class SendMsgSkype(unittest.TestCase): @classmethod def setUpClass(cls): options = Options() options.add_argument("--disable-notifications") cls.driver = webdriver.Chrome('./chromedriver.exe', chrome_options=options) cls.driver.implicitly_wait(5) cls.driver.maximize_window() cls.driver.get("https://web.skype.com/ru/")
It works for me. More details here: http://nullege.com/codes/show/src@t@a@TardyParty-HEAD@oxbiz.py/21/selenium.webdriver.Chrome
The one and only working solution I've come across so far is this:
from selenium.webdriver.chrome.options import Options chrome_options = webdriver.ChromeOptions() prefs = {"profile.default_content_setting_values.notifications" : 2} chrome_options.add_experimental_option("prefs",prefs) driver = webdriver.Chrome(chrome_options=chrome_options)
no answer has been accepted yet, this following code works for me
ruby, rspec, capybara
Capybara.register_driver :selenium_chrome do |app| prefs = {"profile.managed_default_content_settings.notifications" => 2,} caps = Selenium::WebDriver::Remote::Capabilities.chrome(chrome_options: { prefs: prefs }) Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: caps) end Capybara.javascript_driver = :selenium_chrome
try { // Check the presence of alert Alert alert = driver.SwitchTo().Alert(); // if present consume the alert alert.Accept(); } catch (NoAlertPresentException ex) { //code to do if not exist. }
if you play with Ruby and Capybara try this code
Capybara.register_driver :chrome_no_image_popup_maximize do |app| # 2: disable, other than 2 means enable it preferences = { "profile.managed_default_content_settings.notifications" => 2, "profile.managed_default_content_settings.images" => 2, "profile.managed_default_content_settings.popups" => 2 } caps = Selenium::WebDriver::Remote::Capabilities.chrome( 'chromeOptions' => { 'prefs' => preferences, } ) args = [ "--start-maximized" ] Capybara::Selenium::Driver.new(app, {:browser => :chrome, :desired_capabilities => caps, :args => args}) end Capybara.default_driver = :chrome_no_image_popup_maximize Capybara.javascript_driver = :chrome_no_image_popup_maximize
Facebook authentication window displays an overlay that covers the continue as [username] button.
This makes the continue button un-clickable. To circumvent that problem, you can hide those layers programmatically using JavaScript (not recommended) using this code (don't do this).
// DO NOT USE THIS CODE. function forceClickSetup(targetSelector) { return browser.selectorExecute("div", function(divs, targetSelector) { var button = document.querySelector(targetSelector); for(var i = 0; i
Or instead, you can dismiss the notifications dialog, after which facebook will uncover the continue button. But before wildly hitting Escape
at the browser, first make sure that the continue button has been shown.
// USE THIS CODE. browser.waitForVisible("[name=__CONFIRM__]"); browser.keys("Escape"); // Dismiss "notifications" dialog box. var confirmButtonSelector = "[name=__CONFIRM__]";
This solution is really Matthijs' (see comments above)