0

I have a situation (during a selenium test), in which the user will receive a security code. The user must then input the security code before being allowed to continue.

I'm not too sure on how I can get the value the user inputted. I browsed around the selenium docs and came up with this. Unfortunately, it doesn't quite work.

    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("window.promptResponse=prompt('Please enter the security code')");

    if(isAlertPresent()) {
        // switch to alert
        Alert alert = driver.switchTo().alert();

        // sleep to allow user to input text
        Thread.sleep(10000);

        // this doesn't seem to work 
        code = (String) js.executeScript("return window.promptResponse");

        alert.accept();

Can someone point me in the correct direction?

1
  • Seems like something similar to CAPTCHA which is mostly there to avoid automation. Commented Oct 28, 2014 at 7:59

1 Answer 1

1

It seems you have to accept and close the prompt first, before being able to store and use the value

    alert.accept();
    code = (String) js.executeScript("return window.promptResponse");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.