excel - Selenium VBA中的GetAttribute用于样式
问题描述
我正在使用 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")
,它对我不起作用任何想法
解决方案
getAttribute("style")
应该可以工作,但您必须诱导一个服务员让元素在HTML DOM中出现/可见。
Debug.Print post.Item(i).getAttribute("style")
准确地说,要从元素中提取样式属性的值,可以使用getCssValue()
如下方法:
Debug.Print post.Item(i).getCssValue("z-index")
Debug.Print post.Item(i).getCssValue("top")
Debug.Print post.Item(i).getCssValue("left")
Debug.Print post.Item(i).getCssValue("width")
Debug.Print post.Item(i).getCssValue("height")
getAttribute("innerHTML")
get_attribute("innerHTML")
可用于读取 innerHTML 或任何节点/ WebElement中的文本
您可以在使用 Selenium 的文本和内部 HTML 之间的区别中找到详细讨论
参考
您可以在以下位置找到一些相关的讨论:
推荐阅读
- clang - libc++ 是否向后兼容旧版本?
- django - django 联系页面错误地发送电子邮件
- mocha.js - 如何在 Cypress It() 命令描述中使用模板文字
- css - 生成字体的 SCSS @each 规则不适用于输出
- php - 爆炸功能还是其他原因?
- python - 在 Plotly 中为具有相应边的每个节点添加图例
- angular - 如何使用 NPM 在 Angular 10 中安装引导 ngx
- unit-testing - Elixir 的 Mix 负载源是否可能来自多个路径?
- python - Python pandas在时间列上合并数据帧意外结果
- c++ - 关于这个递归函数的问题