【问题标题】:Handling dynamic text change in span tag处理 span 标签中的动态文本更改
【发布时间】:2017-09-27 06:38:02
【问题描述】:

单击提交按钮后,我收到以下两条消息之一:

1) 发现的状态信息。请验证订单 PO001007 然后推送。

2) 订单号的 Tally 推送 - PO001008 成功

对于成功条件,我正在使用这个 xpath:

.//*[@id='wrap']/div[2]/div[2]/div/div[4]/span[text()='Tally push of order no - PO001008 successful']

但是里面的文字每次都在变化,所以如果我用这个xpath:

.//*[@id='wrap']/div[2]/div[2]/div/div[4]/span

即使失败的条件也会通过。有人知道如何处理 span 标签内的这种动态文本变化吗?

下面是我的成功和失败条件的html代码:

<div class="alert alert-info alert-dismissable">
<button class="close" type="button" data-dismiss="alert" aria-hidden="true">×</button>
<span>Invalid states information found. Please verify the order PO001007 and then push.</span>
</div>
-----------------------------------------

<div class="alert alert-info alert-dismissable">
<button class="close" type="button" data-dismiss="alert" aria-hidden="true">×</button>
<span>Tally push of order no - PO001008 successful</span>
</div>

【问题讨论】:

  • 你想找到什么请告诉我
  • 我想定位
    Tally push of order no - PO001008 成功
    这个元素在 span 中的文本每次都会改变
  • 好的,:) 亲爱的
  • 知道如何处理这个问题
  • 我发布了一个 xpath 试试这个

标签: selenium xpath selenium-webdriver webdriver ui-automation


【解决方案1】:

你必须使用这个 xpath

试试这个:

对于不成功的订单使用这个

 ///button[@class='close']/following::span[contains(text(),'Invalid')]

为了成功的订单使用这个

//button[@class='close']/following::span[contains(text(),'order no')]

【讨论】:

  • 如果我收到失败消息 - 此 div 将替换为以下 div
    发​​现无效状态信息。请验证订单 PO001007 然后推送。
    所以这个 xpath 也在定位这个 div
  • 所以在我的成功条件下,即使失败消息也是如此
  • 两个结果都在同一个页面上
  • 它在 span 后跟 span 时工作,如果同一页面上有多个 span,则必须更改它
  • 我将收到任何一条消息,并且该消息将显示在同一页面的同一位置
猜你喜欢
  • 2012-10-10
  • 2017-09-21
  • 1970-01-01
  • 2017-03-14
  • 2011-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多