Vbscript 通过Instr函数进行比较帮助
我想在VB6中将Vbscript 通过Instr函数进行比较帮助,vbscript,qtp,Vbscript,Qtp,我想在VB6中将int转换为string,并将string解析为Instr函数,但我无法这样做,以下是我的代码: '.WebElement("total_Count").GetROProperty("innertext")=1 - 10 de 31 candidatos 'This is the value in innertext, and i want to compare the 31 totalCount=31 CStr (totalCount) If InStr(t
int
转换为string
,并将string
解析为Instr
函数,但我无法这样做,以下是我的代码:
'.WebElement("total_Count").GetROProperty("innertext")=1 - 10 de 31 candidatos
'This is the value in innertext, and i want to compare the 31
totalCount=31
CStr (totalCount)
If InStr(totalCount,.WebElement("total_Count").GetROProperty("innertext"))>0Then
MsgBox "Found"
Reporter.ReportEvent micPass,"DBVerification","TotalCount Verified From DB"
Else
MsgBox "Not Found"
Reporter.ReportEvent micFail,"DBVerification","TotalCount Not Verified From DB"
End If
感谢您的帮助除非模块/表单/类顶部使用了
选项比较文本
,否则VB6上的比较区分大小写;但在这种特殊情况下,这并不重要。另外,CStr(totalCount)
没有分配任何内容,也没有将totalCount更改为字符串;它返回一个字符串
totalCount=31
If InStr(lcase(CStr(totalCount)),lcase(.WebElement("total_Count").GetROProperty("innertext")))>0 Then
MsgBox "Found"
Reporter.ReportEvent micPass,"DBVerification","TotalCount Verified From DB"
Else
MsgBox "Not Found"
Reporter.ReportEvent micFail,"DBVerification","TotalCount Not Verified From DB"
End If
如果totalcount=31且innertext包含1,那么为什么不将它们作为数字进行比较呢?如果totalcount=31且innertext包含1,则会得到True,这肯定不是您想要的结果。交换Instr()函数的参数:
InStr(.WebElement(“total_Count”).GetROProperty(“innertext”),totalCount)>0
现在您正在查看31是否在您的innertext中。您不必使用cStr()
、lCase()
或其他东西,VBScript将为您提供这些功能
编辑:您真正想让它正常工作的是正则表达式,当然:
Dim regEx, matches, actualTotal
set regEx = new RegExp
regEx.Global = True
regEx.pattern = "\d+ - \d+ de (\d+) candidatos"
Set matches = regEx.Execute(Value)
actualTotal = matches(0).submatches(0)
现在,您可以将actualTotal与预期的总数进行比较,而不必担心数字是否在字符串的其余部分。
例如:
“31-40 de 42 Candimatos”将导致假阳性。使用RegExp可以防止这种行为。请您详细解释一下您想做什么。是否要检查
.WebElement(“total_count”)
中的字符串是否包含文本31
?这与您的评论不一致10 de 31 Candidates
FYI QTP测试是VBScript而不是VB6提问者确实在VB6下标记了它,但这是不正确的。这是VBScript。在VBScript中,不必使用lcase
数字将其转换为。。。数字,我怀疑你也必须在VB6中这样做。查看他的评论,应用程序会返回类似“31个总数中的结果1到10个”的内容。他想看看字符串中是否有31,看看总数是否正确。