如何从警报框中获取文本 [英] How to get text from the alert box

查看:106
本文介绍了如何从警报框中获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从下面显示的警报框中获取文本.该警报框显示在网址栏上方. 以下是我的框架声明的示例:

I need to grab a text from the alert box shown below. This alert box appears hovering above the url bar. Below is an example of my framework assertion:

verifyDisplay("'"+ driver.switchTo().alert().getText() + "'", By.xpath("xpath").

我不确定如何捕获此警报框的xpathidname,因为没有.

I am not sure, how to grab xpath, id, name of this alert box, since there is none.

非常感谢您的帮助.

推荐答案

警报"界面中有一个方法,可为您提供警报框消息的文本.如下:

There is a method in Alert interface which gives you the text of the alert box message. As below:

Alert alert = driver.switchTo().alert();
alert.getText();

Alert API Javadoc

如果您需要进一步的帮助,请告诉我.

Let me know if you need further help.

这篇关于如何从警报框中获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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