question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WDA throwing exception when no alert is present

See original GitHub issue

The problem

Using ExpectedConditions.alertIsPresent() to process alerts on app launch. As of appium 1.7.2, GET alert/text throws an exception if there is no alert present. This prevents the code from working properly as we can never reach the set timeout due the WebDriverException thrown.

Environment

  • Appium version (or git revision) that exhibits the issue: 1.7.2
  • Last Appium version that did not exhibit the issue (if applicable): I think 1.7.1. If not it was the previous release
  • Desktop OS/version used to run Appium: Mac High Sierra
  • Node.js version (unless using Appium.app|exe): 9.5.0
  • Mobile platform/version under test: iOS 11.2.X
  • Real device or emulator/simulator: Both
  • Appium CLI or Appium.app|exe: Both

Details

WDA pushing this issue back onto Appium. https://github.com/facebook/WebDriverAgent/issues/857

In the meantime I just put the code into a try/catch block, but its very messy as i essnetially have to code my own timer.

Link to Appium logs

Pasting just a snippet here

[HTTP] --> GET /wd/hub/session/21fd42d2-155b-43c8-8fb1-5aa5e2f21350/alert_text {}
[debug] [MJSONWP] Calling AppiumDriver.getAlertText() with args: ["21fd42d2-155b-43c8-8fb1-5aa5e2f21350"]
[debug] [XCUITest] Executing command 'getAlertText'
[debug] [XCUITest] Setting custom timeout to 180000 ms for "getAlertText" command
[debug] [JSONWP Proxy] Proxying [GET /alert/text] to [GET http://localhost:8100/session/6B2E6ABD-FFCE-4FC2-96B7-93751C9E222D/alert/text] with no body
[debug] [JSONWP Proxy] Got response with status 200: "{\n  \"value\" : {\n\n  },\n  \"sessionId\" : \"6B2E6ABD-FFCE-4FC2-96B7-93751C9E222D\",\n  \"status\" : 27\n}"
[MJSONWP] Encountered internal error running command: Error: An attempt was made to operate on a modal dialog when one was not open.
    at JWProxy.command$ (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:176:15)
    at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
    at <anonymous>
[HTTP] <-- GET /wd/hub/session/21fd42d2-155b-43c8-8fb1-5aa5e2f21350/alert_text 500 438 ms - 242

Code To Reproduce Issue [ Good To Have ]

in Java, this will throw a WebDriverException every time it checks, instead of checking for the alert until finding one (or throwing a TimeoutException)

public static void main(String[] args) {
        //Driver was initialized and app is launched
        final WebDriverWait wait = new WebDriverWait(this.driver, 30);
        wait.until(ExpectedConditions.alertIsPresent());
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14

github_iconTop GitHub Comments

1reaction
mykola-mokhnachcommented, Mar 5, 2018

@jamesvanhorn Can you reinstall your beta and try again? The problem should be addressed now

1reaction
jamesvanhorncommented, Mar 2, 2018

Does not work in appium@beta either. @jazzpetzah the temporary fix is to wrap the ExpectedCondition in a try/catch like this

try {
    final WebDriverWait wait = new WebDriverWait(this.driver, 30);
    wait.until(ExpectedConditions.alertIsPresent());
} catch (final WebDriverException ex) {
    if (ex.getMessage().contains("An attempt was made to operate on a modal dialog when one was not open")) {
       //Figure out some logic to know when to exit
       //break;
    } else {
        throw ex;
    }
}

The timeout will never be reached if you catch the exception, so you need to implement some type of counter yourself to figure out when you want to exit. Then wrap all this in a while loop.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is NoAlertPresentException in Selenium? - Educative.io
Generally, the Selenium program driver tries to switch to an alert box or pop-up that is displayed on top of the webpage when...
Read more >
selenium - How to check if an alert exists using WebDriver?
And it's a better way when most of your test cases is NO dialog present (throwing exception is expensive). Share.
Read more >
An instance of popup view already exists in the application
I have used a popup in my WDA application which gets opened on the click of the button. Whenever the application is launched...
Read more >
Unable to accept iOS permission alerts from ... - Appium Discuss
Unable to accept Noification permission alert via appium automation code Tried multiple ways but could not resolve the issue.
Read more >
appium-xcuitest-driver - npm
appium:updatedWDABundleId, Bundle id to update WDA to before building and ... This option helps to avoid Keyboard is not present error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found