TA的每日心情 | 开心 2024-10-4 10:34 |
---|
签到天数: 1208 天 连续签到: 1 天 [LV.10]测试总司令
|
里面各价格之和是否正确,其实就是用innertext 取到每一行 然后拆分价格和数目,然后在FormatNumber格式化一下拆分的函数是从网上找的
- Dim oWebElements,oDesc
- Set oDesc=description.Create()
- oDesc("micClass").value="WebElement"
- oDesc("html tag").value="span"
- oDesc("class").value="p-price"
- set oWebElements= Browser("奶粉 - 商品搜索 - 京东").Page("奶粉 - 商品搜索 - 京东").ChildObjects(oDesc)
- oCount=oWebElements.count()
- Dim tempObj
- Dim MyString, MyArray, Msg
- For i=0 To oCount-1
- Set tempObj = oWebElements.Item(i)
- sliptString=tempObj.GetROProperty("innertext")
- intPrice=between(sliptString,"¥","×")
- intNums=between(sliptString,"×","")
- intTotal=intTotal+(intPrice*intNums)
- Next
- msgbox "有"& oCount &"种商品"
- actPrice=between(Browser("奶粉 - 商品搜索 - 京东").Page("奶粉 - 商品搜索 - 京东").WebElement("共计").GetROProperty("innertext"),"¥","")
- If FormatNumber(intTotal,2)=FormatNumber(actPrice,2) Then
- Reporter.ReportEvent micPass, "共计相等", "共计价格为:"& actPrice
- Else
- Reporter.ReportEvent micFail, "共计不相等", "共计价格为:"& actPrice &"各商品价格之和为:"& intTotal
- End If
复制代码
- '得到两个字符串中间的字符串。
- '例如:
- 'text="人民币300元",tBefore="人民币",tAfter="元"
- '使用between(text,tBefore,tAfter)得到300.
- Public Function between(words,wordBefore,wordAfter)
- t1=InStr(words,wordBefore)
- If t1=0 Then
- between=words
- Else
- L1=Len(wordBefore)
- wordsRight=Right(words,Len(words)-t1-L1+1)
- t2=InStr(wordsRight,wordAfter)
- If t2=0 Then
- wordAfter=""
- End If
- If wordAfter="" Then
- t2=Len(wordsRight)+1
- Else
- t2=InStr(wordsRight,wordAfter)
- End If
- needWord=Left(wordsRight,t2-1)
- ' needWord=Mid(words,t1+L1,t2-t1-L1)
- between=needWord
- End If
- End Function
复制代码 |
|