Ricerca…


Esempio di Python di Accepting alert

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()

Estensioni 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;
}

Come usare:

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

Giava

Per semplice avviso:

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

Per avviso rapido:

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();

Per avviso di conferma:

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

Un altro modo per farlo è avvolgere il codice all'interno di 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
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow