如何获取几秒钟内消失的通知的xpath?

时间:2018-01-12 13:31:47

标签: javascript java selenium xpath

如何收到错误消息: - 身份验证错误,请与您的服务台联系

这是我的副本元素:

<div class="alert alert-error dismissible" 
role="alert" 
data-rendered="true" 
style="overflow: hidden; height: 5.74723px; 
padding-top: 1.43681px; margin-top: 0px; 
padding-bottom: 1.43681px; 
margin-bottom: 0px;"><button class="icon-dismiss" aria-label="Dismiss" type="button"></button>
<p><strong>Error:&nbsp;</strong>authentication error with Transaction contact your help desk</p></div>

我想要xpath

2 个答案:

答案 0 :(得分:0)

在Chrome浏览器

下,Xpath工作正常
Percent
100.0%
50.0%
20.0%

答案 1 :(得分:0)

要获取错误消息authentication error with Transaction contact your help desk,您可以使用以下代码块:

String text = driver.findElement(By.xpath("//div[@class='alert alert-error dismissible']//p")).getAttribute("innerHTML");
String[] my_text = text.split("(?=authentication)");
System.out.println(my_text[1]);