简体   繁体   English

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

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

I am trying to access the below attributes of the web element我正在尝试访问 web 元素的以下属性

enter image description here在此处输入图像描述

Is there any way in karate where I can grab the CSS style attribute of the UI elements, like how we have in selenium getCssValue("font-size")空手道有什么方法可以获取 UI 元素的 CSS 样式属性,就像我们在 selenium getCssValue("font-size")

I have tried the below code我试过下面的代码

  • print attribute('#eg01SubmitId', 'font-size')打印属性('#eg01SubmitId', 'font-size')

but it's giving an empty value但它给出了一个空值

Just use JS please, Karate does not need all these fancy API-s.请使用 JS,空手道不需要所有这些花哨的 API。

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

And then using normal DOM API-s you can do this:然后使用普通的 DOM API-s 你可以这样做:

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

I referred this article: https://zellwk.com/blog/css-values-in-js/我参考了这篇文章: https://zellwk.com/blog/css-values-in-js/

EDIT: if you read the last link, you should have realized that if the styles come from a CSS class etc, you should use getComputedStyle()编辑:如果您阅读最后一个链接,您应该已经意识到,如果 styles 来自 CSS class 等,您应该使用getComputedStyle()

so try this:所以试试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM