如何读取硒显示在UL类上弹出的窗口中显示的文本 [英] How to read text displayed on the window pop up on UL class by selenium

查看:95
本文介绍了如何读取硒显示在UL类上弹出的窗口中显示的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Java阅读Web驱动程序中弹出窗口上显示的文本.我能够处理要关闭的弹出窗口.我不知道如何阅读弹出窗口中显示的文本并在控制台中打印.

I need to read the text displayed on the popup window in Web driver using Java. I am able to handle the popup window for closing. I don't know how to read the text displayed on Popup window and print it in Console.

HTML:

<ul class="traceInner"><li class="traceHead"><span><input type="checkbox" class="chkall hand">奖期</span><em>追号倍数</em><em>追号状态</em><em>注单详情</em></li><li><span><input type="checkbox" rel="20151119031YCL02WY0001" class="hand disabled" disabled="disabled" name="2015316">2015316</span><em>1</em><em><label>已完成</label></em><em><a class="hand traceDetails" data-id="20151119031YCL02WY0001" rel="434">详情</a></em></li><li><span><input type="checkbox" rel="" class="hand" name="2015317" 追号中="">2015317</span><em>1</em><em><label>进行中</label></em><em>&nbsp;</em></li></ul>

我需要在标签中获得已完成的标签文本.

I need to get the lable text of 已完成 in label.

我的代码:

ConfirmationPlaceBet_Page.verification_ZhuiHao2(driver).getText();

推荐答案

1.您可以将此xpath用于一般命令:

1.You can use this xpath for general :

xpath = //label[text()= '已完成']

2.如果您的ul元素太多,请使用以下xpath:

2.If you have too many ul element then use this xpath :

xpath = //ul[@class='traceInner']//label[text()= '已完成']

3.如果要获取第一个标签元素,请使用以下xpath:

3.If you want to get first label element then use this xpath :

xpath = (//ul[@class='traceInner']//label)[1]

注意:如果您想获得第二个标签,请传递2而不是1

Note : Pass 2 instead of 1 if you want to get second label

4.如果要获取标签列表,请使用以下xpath:

4.If you want to get list of labels then use this xpath :

 xpath = //ul[@class='traceInner']//label

这是您对如何获取文字"的回答:

Here is your answer of "How to get text" :

 String text = driver.findElement(By.xpath("your Xpath")).getText();

警告

对于Web元素列表,您必须像这样使用:

For List of web elements you have to use like this :

 String text_1 = driver.findElement(By.xpath("your Xpath of List")).get(0).getText();

这篇关于如何读取硒显示在UL类上弹出的窗口中显示的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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