【问题标题】:Vba Selenium: Check if html tag is present in the source codeVba Selenium:检查源代码中是否存在html标签
【发布时间】:2014-04-08 21:35:08
【问题描述】:

这是我的问题,我有一个使用 selenium 的 Vba 代码,它通过很多 url 循环。我需要验证是否存在一个标签,如果是,我需要代码来恢复下一个,问题是我刚刚开始使用 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

【问题讨论】:

  • 这里少了几行代码,我觉得^^

标签: vba excel selenium selenium-webdriver


【解决方案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

【讨论】:

  • 谢谢你回答理查德,你是对的,我错了,但即使改变 IE.findElementsByClassName("fontdn").Size() > 0 总是返回大于 0 因为它每次都退出循环,为了确保我检查了源代码并且没有这样的“fontdn”类名,所以我对 .size 属性感到犹豫,因为它返回包含该类名的标签数量。
  • 我四处走走,我找到了获得它的方法。谢谢理查德
  • 这就是我得到它的方式。 TagCheck = IE.findElementByClassName("thumbs").getAttribute("id") If TagCheck = "thumbs" Then exit for
猜你喜欢
  • 1970-01-01
  • 2021-07-08
  • 2014-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-05
相关资源
最近更新 更多