Haz todo lo posible por entender el código de forma correcta antes de utilizarlo a tu proyecto y si tquieres aportar algo puedes decirlo en los comentarios.
Solución:
Por favor, siga los pasos a continuación:
A) UTILIZANDO JAVA:
Para la versión antigua de Chrome (<50):
//Create a instance of ChromeOptions class
ChromeOptions options = new ChromeOptions();
//Add chrome switch to disable notification - "**--disable-notifications**"
options.addArguments("--disable-notifications");
//Set path for driver exe
System.setProperty("webdriver.chrome.driver","path/to/driver/exe");
//Pass ChromeOptions instance to ChromeDriver Constructor
WebDriver driver =new ChromeDriver(options);
Para la nueva versión de Chrome (>50):
//Create a map to store preferences
Map prefs = new HashMap();
//add key and value to map as follow to switch off browser notification
//Pass the argument 1 to allow and 2 to block
prefs.put("profile.default_content_setting_values.notifications", 2);
//Create an instance of ChromeOptions
ChromeOptions options = new ChromeOptions();
// set ExperimentalOption - prefs
options.setExperimentalOption("prefs", prefs);
//Now Pass ChromeOptions instance to ChromeDriver Constructor to initialize chrome driver which will switch off this browser notification on the chrome browser
WebDriver driver = new ChromeDriver(options);
Para 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("http://google.com");
B) UTILIZANDO PITÓN:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
option = Options()
option.add_argument("--disable-infobars")
option.add_argument("start-maximized")
option.add_argument("--disable-extensions")
# Pass the argument 1 to allow and 2 to block
option.add_experimental_option("prefs",
"profile.default_content_setting_values.notifications": 1
)
driver = webdriver.Chrome(chrome_options=option, executable_path='path-of-
driverchromedriver.exe')
driver.get('https://www.facebook.com')
C) UTILIZANDO C#:
ChromeOptions options = new ChromeOptions();
options.AddArguments("--disable-notifications"); // to disable notification
IWebDriver driver = new ChromeDriver(options);
Este no es un cuadro de alerta, por lo que no puede manejarlo usando Alert
esta es una notificación del navegador Chrome. Para desactivar esta notificación del navegador, debe crear un mapa de preferencias de Chrome con la opción Chrome como se muestra a continuación:
//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
Espero eso ayude..:)
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/")
Esto funciona para mi. Más detalles aquí: http://nullege.com/codes/show/[email protected]@[email protected]@oxbiz.py/21/selenium.webdriver.Chrome
Si te apasiona la informática, puedes dejar un enunciado acerca de qué te ha gustado de este enunciado.