我正在使用Selenium Wrapper for Visual Basic来自动化Chrome浏览器。
我需要根据先前存储的字符串变量(发票)中的字符串验证表格中的文本。
简化的HTML示例:
<th scope="row" class=" dataCell ">
<a href="link-to-follow" onclick="searchResultClick.mousedown(this, event)" onmousedown="searchResultClick.mousedown(this, event)">Link Text</a>
</th>
<td class=" dataCell ">Text to be verified</td>
<td class=" dataCell "> </td>
我在Excel VBA中尝试过此操作无效:
Sub SearchForInvoice()
Dim driver As New SeleniumWrapper.WebDriver
Dim invoice As String
invoice = "Text to be verified"
If driver.verifyTextPresent(invoice) = True Then
MsgBox("Success")
Else
End If
End Sub
出现错误消息&#34;运行时错误&#39; 13&#39;:类型不匹配&#34;
提前感谢您提供的任何帮助。编程还是比较新的。
答案 0 :(得分:0)
我写了很多VBA
代码已经很久了。然而,你的问题看起来很简单。
Sub SearchForInvoice()
Dim driver As New SeleniumWrapper.WebDriver
Dim invoice As String
invoice = "Text to be verified"
'You are doing driver.verifyTextPresent on driver itself. It should be on an element instead.
'Or, simply finding the element with text based xpath search is enough as well.
If driver.findElementByXPath("//td[.='Text to be verified']").size() > 0 Then
MsgBox("Success")
End If
End Sub