【发布时间】:2020-10-02 00:03:20
【问题描述】:
我正在 VBA 中处理 selenium,并且我已经存储了一个变量“post”来存储所有出现的特定元素
Dim post As Object
Set post = .FindElementsByCss("#DetailSection1")
Dim i As Long
For i = 1 To post.Count
Debug.Print post.Item(i).getAttribute("style")
Next i
我需要从元素中提取样式值
<div id="DetailSection1" style="z-index:3;clip:rect(0px,746px,32px,0px);top:228px;left:0px;width:746px;height:32px;">
</div>
我还需要在即时窗口中打印 innerHTML,当我使用 getAttribute("innerHTML") 时,它对我不起作用
任何想法
【问题讨论】:
-
你不应该使用通过 Id 获取元素而不是通过 CSS 获取它吗?
-
我的 id 不是唯一的。我有 22 个这个 id
-
我不记得但 Selenium 的基本方法不是 Attribute("") 而不是 getAttribute? getAttribute 用于 nodeList 而不是 webElement 中的节点。 IIRC,但确认会很好。
-
非常感谢您的精彩提示。这对我有用
Debug.Print .FindElementByCss("#DetailSection1").Attribute("outerHTML")
标签: excel vba selenium selenium-webdriver getcomputedstyle