How to handle 2 alert in Selenium WebDriver

I have an automation scenario to perform a content searching. The problem happen in the search result screen where there are 2 Javascript alert popup appears at nearly the same time. I said nearly because the popup window appears one by one, not all of them at once. I managed to handle the first one, but not with the second one. NoAlertPresentException happened for the second alert handler code.

Here’s where the alert happened:

    public WSSPage enterAndSearchContent(String title) {
        waitWSSPageLoaded();
        waitForElementTextWithEnter(searchTextField, title);
        waitWSSPageLoaded();
        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.alertIsPresent());
        Alert alert = driver.switchTo().alert();
        alert.dismiss();
        wait.until(ExpectedConditions.alertIsPresent()); //NoAlertPresentException happened here
        Alert alert2 = driver.switchTo().alert();
        alert2.dismiss();
        return PageFactory.initElements(driver, WSSPage.class);
    }

I alse tried using alert.dismiss(); twice but still it gives NoAlertPresentException at the second alert.dismiss(); like the below code:

    public WSSPage enterAndSearchContent(String title) {
        waitWSSPageLoaded();
        waitForElementTextWithEnter(searchTextField, title);
        waitWSSPageLoaded();
        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.alertIsPresent());
        Alert alert = driver.switchTo().alert();
        alert.dismiss();
        alert.dismiss(); //NoAlertPresentException happened here
        return PageFactory.initElements(driver, WSSPage.class);
    }

When I try manually dismissing the alert, the second alert appears almost instantly. I guess the problem is the code can’t catch the second alert because it was too fast?
Is there any workaround for this problem? Thank you.

Note:
I’m using Firefox