Vba Selenium:检查源代码中是否存在html标记

时间:2014-04-08 21:35:09

标签: vba excel-vba selenium selenium-webdriver excel

这是我的问题,我有一个使用selenium的Vba代码循环通过很多网址。我需要验证是否存在一个标签,如果是,我需要接下来要恢复的代码,问题是我刚刚开始使用selenium,而且我不知道如何验证标签是否存在于给定标签中源代码。

这是标签:

<a class="fontdn" id="fontdn" href="#" title="Zoom Out (Key: -)">Zoom Out (Key: -)</a>

这是我到目前为止的Vba-selenium代码,这假设返回带有此id的元素数但不起作用。

If IE.findElementsByTitle("Zoom Out (Key: -)").Size() > 0 Then Exit For

1 个答案:

答案 0 :(得分:1)

我检查了Excel VBA的包装器,我在代码中看不到findElementsByTitlehttps://code.google.com/p/selenium-vba/source/browse/trunk/wrapper/WebElement.cs

你应该可以使用:

If IE.findElementsByClassName("fontdn").Size() > 0 Then Exit For

修改

我查看了包装器源代码,findElementsByClassName返回一个数组。从我所知道的,Excel VBA阵列使用Length,而不是Size()

也许这个?

If IE.findElementsByClassName("fontdn").Length > 0 Then Exit For