空手道 - UI 自动化 - 是否可以获取 Web 元素的 Css 样式属性

Karate - UI Automation - Is it possible to grab Css style attributes of web element

我正在尝试访问网络元素的以下属性

enter image description here

在空手道中有什么方法可以获取 UI 元素的 CSS 样式属性,就像我们在 selenium getCssValue("font-size")

我试过下面的代码

但它给出了一个空值

请用JS,空手道不需要那么多花哨的东西API-s.

请参阅 script() 的文档:https://github.com/intuit/karate/tree/master/karate-core#script

然后使用正常的 DOM API-s 你可以这样做:

* def displayStyle = script('.Popover', "_.style['display']")

我引用了这篇文章:https://zellwk.com/blog/css-values-in-js/

编辑:如果你读了最后一个 link,你应该意识到如果样式来自 CSS class 等,你应该使用 getComputedStyle()

所以试试这个:

* print script('.demo-btn', "function(e){ return getComputedStyle(e)['font-size'] }")