1

I am creating a test project where when clicking on a button system pops-up a window where I need to click OK but unable to do using the following code:

@Test
public void testAddNewUserMakeSuperUser() throws Exception {
    driver.get("https://webqa.searshc.com/ssod/Admin/createUser.html");
    driver.findElement(By.id("saveUserDetails")).click();
    Alert alert = driver.switchTo().alert();
    System.out.println(alert.getText());
    alert.accept();
}

I have used

executeScript = ((JavascriptExecutor) driver).executeScript("window.confirm = function(msg) { return true; }");

also... but I am unable to run this.

4

3 回答 3

0

您应该首先测试单击之前页面上是否存在警报。

像这样:

    public static bool IsAlertPresent(this IWebDriver driver)
    {
        try
        {
            driver.SwitchTo().Alert();
            return true;
        }
        catch
        {
            return false;
        }
    }

接着:

    public static void ConfirmAlert(this IWebDriver driver)
    {
        driver.SwitchTo().Alert().Accept();
    }
于 2013-07-02T09:47:41.017 回答
0

这对我有用 executeScript = ((JavascriptExecutor) driver).executeScript("window.confirm = function(msg) { return true; }");

于 2013-07-04T10:42:06.547 回答
-1

请看以下链接

http://www.thoughtworks-studios.com/twist/2.3/help/how_do_i_handle_popup_in_selenium2.html

我希望这对你有帮助,

于 2013-06-27T11:37:22.257 回答