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?