本文介绍了从Selenium Webdriver中的消息中获取特定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,执行所有操作后,如果按保存按钮,则会收到以下消息.

In my application, after performing all the action, if i press save button, i'm receiving the below message.

Deal 0000195734 has been savedSales order 12345 has been created

Deal 0000195734 has been savedSales order 12345 has been created

现在,我只想从上述消息中获取数字值.不是文字部分.例如:0000195734& 12345

Now i want to get only the numeric value from the above message. Not the text part.Eg : 0000195734 & 12345

因为我需要使用上面创建的值进行搜索.

Because i need to search using the above created value.

请找到以下代码

String deal_num = driver.findElement(By.xpath("//div[@id='CLine1']/span[4]")).getText();System.out.println(deal_num);deal_num = Deal 0000195734 has been saved

String deal_num = driver.findElement(By.xpath("//div[@id='CLine1']/span[4]")).getText();System.out.println(deal_num);deal_num = Deal 0000195734 has been saved

我将Java与Selenium Web Driver结合使用.

I am using java with Selenium Web Driver.

请建议

关于,西瓦

推荐答案

字符串deal_num =交易0000195734已保存.

您可以通过两个步骤轻松地替换数字值前后的字符.

You can easily replace characters before and after numeric values in two steps.

第一步将数字值前面的字符替换为空格.

deal_num= deal_num.replace("Deal "," ");

第二步将数字值后面的字符替换为空格.

deal_num= deal_num.replace(" has been saved"," ");

以同样的方式,您可以对销售订单的第二条消息进行处理.

In the same way you can do it for second message of Sales order.

  • 记住要实现相同的目标,除了我自己的方法外,还有其他方法建议您是我找到的最简单的方法.
  • Remember to achieve the same there are also other ways but the one isuggested you is the most easiest way i found.

这篇关于从Selenium Webdriver中的消息中获取特定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 08:14