【问题标题】:How to get xpath for notifications that disappear within few seconds?如何获取在几秒钟内消失的通知的 xpath?
【发布时间】:2018-01-12 13:31:46
【问题描述】:

如何获取错误消息:- 交易的身份验证错误联系您的帮助台

这是我的复制元素:

<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

【问题讨论】:

  • 在这里要求解决方案不是一件好事,看到我们您的解决方案并看到我们为什么它不起作用。
  • 欢迎来到 Stack Overflow!请参阅:How do I do X? SO 的期望是,提出问题的用户不仅会进行研究以回答他们自己的问题,还会分享该研究、代码尝试和结果。这表明您已经花时间尝试帮助自己,它使我们免于重复明显的答案,最重要的是它可以帮助您获得更具体和相关的答案!另见:How to Ask

标签: javascript java selenium xpath


【解决方案1】:

要获取错误消息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]);

【讨论】:

  • 感谢您的代码运行正常。
【解决方案2】:

Xpath 在 Chrome 浏览器中运行良好

 //div/p/text()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多