硒*读取*提示中的文本 [英] Selenium *read* text in prompt

查看:73
本文介绍了硒*读取*提示中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Selenium实施网络测试.在一种情况下,我们的应用程序带有一个浏览器提示.可以通过以下方式处理浏览器提示:

We're using Selenium for implementing web tests. In one scenario, our application comes up with a browser prompt. It is possible to handle browser prompts with:

var alert = driver.SwitchTo().Alert();
alert.Accept(); // accept prompt
alert.Dismiss(); // dismiss prompt
alert.Text; // get text from prompt
alert.SendKeys("text"); // fill out the input element on the prompt

我们是否有可能从输入元素中读取预发布的文本?

Is there any chance we can read the pre-published text from the input element?

推荐答案

prompt()方法如下:

window.prompt("prompt text", "default value");

这将显示一个带有标签的对话框和一个输入文本框,要求用户在其中键入该值.在上面的示例中,标签的文字为提示文字";输入框将预先填充默认值". WebDriver Alert.getText()方法返回提示文本,但是您是对的,目前无法获取默认值.

This will display a dialog box with a label and an input text box where the user is expected to type the value. In the example above, the label will have the text of "prompt text"; the input box will be prepopulated with "default value". The WebDriver Alert.getText() method returns the prompt text, but you're right, there is no way to get the default value at the moment.

这篇关于硒*读取*提示中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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