硒中的部分文本声明和2个变量的比较

问题描述

我遇到了不确定如何解决的问题。我在一页上有客户代码(例如Test095)。我将其存储为var1。而且我必须导航到另一个页面并验证代码是否相同。但是在第二页上,客户代码如下:客户代码:Test095。我存储的是var2。因此,我必须从此处删除客户代码字,以便可以验证var1等于var2。如何摆脱客户代码字?

open |www.link.com
verify title | Page
assert text| css=tr:child(1)-example | Test095
store | css=tr:child(1)-example | var1
open |www.anotherlik.com 
assert text| xpath = //div[@id='myform']/div/div/p[4] | Customer code: Test095
store|xpath = //div[@id='myform']/div/div/p[4] |var2
verify| var2    | ${var1}

解决方法

对字符串使用java inbuit replace()函数。最好也使用trim incase删除空格

 String s = "Customer Code: Test095";
 s = s.replace("Customer Code:","").trim();
 System.out.println(s);

要在Selenium IDE中使其工作 使用命令“执行脚本”,如我在下面的屏幕截图中所使用的

enter image description here

此处“ y”将存储值Test095