硒:如何提示用户输入并使用输入值? [英] Selenium: How to prompt user input and use the input value?

查看:90
本文介绍了硒:如何提示用户输入并使用输入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一种情况(在硒测试期间),用户将收到安全密码.然后,用户必须先输入安全密码,然后才能继续操作.

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?

推荐答案

似乎您必须先接受并关闭提示,然后才能存储和使用值

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");

这篇关于硒:如何提示用户输入并使用输入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆