org.openqa.selenium.NoAlertPresentException: no alert open

MY DZON

My test checks to see if I can send a message to the mail. When I click the send button should check the alert.

My code for alert is:

        Alert alert = driver.switchTo().alert();
        System.out.println(alert.getText());
        alert.accept();
        Assert.assertTrue(alert.getText().contains("Thanks."));

My error is:

Starting ChromeDriver 2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed) on port 13707
Only local connections are allowed.

org.openqa.selenium.NoAlertPresentException: no alert open
  (Session info: chrome=55.0.2883.87)
  (Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 76 milliseconds
Build info: version: 'unknown', revision: '31c43c8', time: '2016-08-02 21:57:56 -0700'
System info: host: 'Gaga', ip: '192.168.1.6', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_101'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed), userDataDir=C:\Users\Dragana\AppData\Local\Temp\scoped_dir6652_7181}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=55.0.2883.87, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: b7131fce27b2ef40f1daff3c82188e7c
Shambu

The code has to wait for alert. Below is the sample code

try {
    WebDriverWait wait = new WebDriverWait(driver, 2);
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    System.out.println(alert.getText());
    alert.accept();
    Assert.assertTrue(alert.getText().contains("Thanks."));
} catch (Exception e) {
    //exception handling
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Exception in thread "main" org.openqa.selenium.NoAlertPresentException: no alert open

org.openqa.selenium.UnhandledAlertException: unexpected alert open

Selenium: NoAlertPresentException

org.openqa.selenium.NoSuchElementException

Getting exception org.openqa.selenium.SessionNotCreatedException

Caused by: org.openqa.selenium.InvalidSelectorException:

Selenide Test fails with org/openqa/selenium/NoSuchSessionException

Firefox - org.openqa.selenium.interactions.MoveTargetOutOfBoundsException

org.openqa.selenium.JavascriptExecutor could be resolved

org.openqa.selenium.SessionNotCreatedException with Appium

java.lang.ClassCastException: org.openqa.selenium.By$ById cannot be cast to org.openqa.selenium.WebElement

org.openqa.selenium.remote.UnreachableBrowserException: - Error selenium Java TestNG

Selenium Actions.movetoElement - org.openqa.selenium.UnsupportedCommandException

Selenium error - org.openqa.selenium.SessionNotCreatedException session created exception

Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: element not interactable

Testing Electron application with org.openqa.selenium in a Java environment (Intellij)

How to troubleshoot intermittent org.openqa.selenium.TimeoutException: timeout

org.openqa.selenium.WebDriverException: Browser failed to start, test in fluentlium

org.openqa.selenium.WebDriverException:java.io.IOException

org.openqa.selenium.InvalidArgumentException: unknown error: unsupported protocol

org.openqa.selenium.InvalidArgumentException: Invalid capabilities using DesiredCapabilities

unable to resolve class reference org/openqa/selenium/WebDriver

How to create a org.openqa.selenium.Cookie with the isSecure flag to false

org.openqa.selenium.NoSuchElementException: Unable to locate element error

Getting org.openqa.selenium.InvalidSelectorException only for Chrome

Exception in thread "main" org.openqa.selenium.InvalidElementStateException:

Cannot resolve constructor FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)

What is causing JBrowserDriver WebDriverException: org/openqa/selenium/security/Credentials

org.openqa.selenium.InvalidSelectorException - [object Text]. It should be an element