Buscar..


Ejemplo de Python de aceptar alerta

from selenium import webdriver

# Create a new webdriver
driver = webdriver.Chrome()
# Get a page that has a popup window (Use mouse to click "try it" button)
driver.get("http://www.w3schools.com/js/tryit.asp?filename=tryjs_alert")
# Accept the opened alert
driver.switch_to.alert.accept()

Extensiones de C # a WebDriver

public static IWebDriver dismissAlert(this IWebDriver driver)
{
    try
    {
        IAlert alert = driver.SwitchTo().Alert();
        alert.Dismiss();
    }
    catch {}
    return driver;
}
public static IWebDriver acceptAlert(this IWebDriver driver)
{
    try
    {
        IAlert alert = driver.SwitchTo().Alert();
        alert.Accept();
    }
    catch { }
    return driver;
}

Cómo utilizar:

driver.acceptAlert();
driver.dismissAlert();

Java

Para simple alerta:

 Alert simpleAlert = driver.switchTo().alert();
String alertText = simpleAlert.getText();
System.out.println("Alert text is " + alertText);
simpleAlert.accept();

Para alerta rápida:

Alert promptAlert  = driver.switchTo().alert();
String alertText = promptAlert.getText();
System.out.println("Alert text is " + alertText);
//Send some text to the alert
promptAlert.sendKeys("Accepting the alert");
Thread.sleep(4000); //This sleep is not necessary, just for demonstration
promptAlert.accept();

Para la alerta de confirmación:

Alert confirmationAlert = driver.switchTo().alert();
String alertText = confirmationAlert.getText();
System.out.println("Alert text is " + alertText);
confirmationAlert.accept();

Otra forma en que puedes hacer esto es envolver tu código dentro de un try-catch:

try{
   // Your logic here.
} catch(UnhandledAlertException e){
  Alert alert = driver.switchTo().alert();
  alert.accept();
}

// Continue.


Modified text is an extract of the original Stack Overflow Documentation
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow