【发布时间】:2016-08-02 23:49:11
【问题描述】:
我有一个问题已经与这个问题相关联,但这个问题是针对不同的方法。
我的网页上有一个文本字符串,在事务完成后会生成一个时间戳 (hhmmss)。
我不能使用 Time.now,因为处理时间会因许多因素而异。
页面上的文字是:
"Your transaction reference number is: 0 16123 (timestamp is here) A1"
我将在元素中查找以阅读测试中的文本:
expect(find(location)).to have_text trans_text
我可以将位置文本设置为变量吗:
trans_text = find(location, text: 'Your transaction reference number is: 0 16123 (timestamp is here) A1')
然后用正则表达式替换时间戳,然后期望时间戳介于两次之间?
我已经尝试过:
trans_text = find(location, text: 'Your transaction reference number is: 0 16123 (\d+) A1')
但没有快乐。我收到以下错误:
Unable to find css "#main > div > div.section-content > div.two-col.retention-success > div.second-col > div.alert-complete > p" with text "Your retention certificate number is: 0 16123 (/d+) A1".
如何输入正则表达式来替换文本的时间戳部分?
谢谢
【问题讨论】:
-
时间戳是什么格式,能举个例子吗?尝试
(\w+)而不是(\d+),甚至是(.*+) -
格式为 (hhmmss)。 “'您的交易参考号是:0 16123 120000 A1')”。 strftime 将是 ('%H%M%S')
-
我已编辑添加显示我遇到的错误
标签: ruby regex selenium-webdriver cucumber capybara