[英]How to read text displayed on the window pop up on UL class by selenium
I need to read the text displayed on the popup window in Web driver using Java. 我需要使用Java阅读Web驱动程序中弹出窗口上显示的文本。 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 : 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> </em></li></ul>
I need to get the lable text of 已完成 in label. 我需要在标签中获取已完成的标签文本。
MY CODE : 我的密码:
ConfirmationPlaceBet_Page.verification_ZhuiHao2(driver).getText();
1.You can use this xpath for general : 1.您可以将此xpath用于general:
xpath = //label[text()= '已完成']
2.If you have too many ul element then use this xpath : 2.如果您的ul元素太多,请使用以下xpath:
xpath = //ul[@class='traceInner']//label[text()= '已完成']
3.If you want to get first label element then use this xpath : 3.如果要获取第一个标签元素,请使用以下xpath:
xpath = (//ul[@class='traceInner']//label)[1]
Note : Pass 2 instead of 1 if you want to get second label 注意:如果要获得第二个标签,则传递2而不是1
4.If you want to get list of labels then use this xpath : 4.如果要获取标签列表,请使用以下xpath:
xpath = //ul[@class='traceInner']//label
Here is your answer of "How to get text" : 这是您对“如何获取文本”的回答:
String text = driver.findElement(By.xpath("your Xpath")).getText();
Warning 警告
For List of web elements you have to use like this : 对于Web元素列表,您必须像这样使用:
String text_1 = driver.findElement(By.xpath("your Xpath of List")).get(0).getText();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.