如何解决空手道UI中的ShadowRoot dom元素访问问题
我正在尝试访问ShadowRoot dom树元素,但是我面临的问题是我无法使用Specific html元素调用.ShadowRoot,因为该元素是动态的(请参见下面的html片段id =“ vaadin-text-field -error-0)。因此,我唯一能做的就是访问上一级的.vaadin-text-field-container类。基本上,下面是html代码段,它返回“错误消息=最多255个字符” ”,然后在我的KarateUI测试中尝试声明该错误消息。到目前为止,我根据之前阅读的论坛查询尝试了以下选项,但是很幸运,我永远无法访问正确的元素,该元素返回文本“最大255个字符”做断言:
尝试1:
* def test = script('.vaadin-text-field-container','_.innerHTML')
* print "Error Message is" + test
输出:
evaluation (js) failed: script('.vaadin-text-field-container','_.innerHTML'),js eval failed twice:(function(){ var fun = function(_){ return _.innerHTML }; var e = document.querySelector(".vaadin-text-field-container"); return fun(e) })(),error: {"type":"object","subtype":"error","className":"TypeError","description":"TypeError: Cannot read property 'innerHTML' of null\n at fun (<anonymous>:1:46)\n at <anonymous>:1:130\n at <anonymous>:1:139","objectId":"{\"injectedScriptId\":3,\"id\":3}"}
尝试2:
* def test = script('//*[@id="vaadin-text-field-error-0"]','_.innerHTML')
* print 'Error Message is :' + test
输出:
evaluation (js) failed: script('//*[@id="vaadin-text-field-error-0"]',js eval failed twice:(function(){ var fun = function(_){ return _.innerHTML }; var e = document.evaluate("//*[@id="vaadin-text-field-error-0"]",document,null,9,null).singleNodeValue; return fun(e) })(),"className":"SyntaxError","description":"SyntaxError: missing ) after argument list",\"id\":3}"}
尝试3:
* match text('#vaadin-text-field-error-0') == '255 characters max'
输出:
evaluation (js) failed: text('#vaadin-text-field-error-0'),js eval failed twice:document.querySelector("#vaadin-text-field-error-0")['textContent'],"description":"TypeError: Cannot read property 'textContent' of null\n at <anonymous>:1:53",\"id\":3}"}
此处的HTML代码段:
<vaadin-text-field class="standardformfield" id="runsetup" tabindex="0" required has-label has-helper has-value invalid has-error-message>
#shadow-root (open)
<div class="vaadin-text-field-container">
<label part="label" id="vaadin-text-field-label-0">Run Name</label>
<div part="input-field" id="vaadin-text-field-input-0">
<slot name="prefix"></slot>
<slot name="input">
<input part="value" tabindex="0" aria-labelledby="vaadin-text-field-label-0 vaadin-text-field-input-0" placeholder="Type here..." required="" aria-describedby="vaadin-text-field-helper-0 vaadin-text-field-error-0" invalid="" aria-invalid="true">
</slot>
<div part="clear-button" id="clearButton" role="button" aria-label="Clear" hidden="true"></div>
<slot name="suffix"></slot>
</div>
<div part="helper-text" id="vaadin-text-field-helper-0">
<slot name="helper">No special characters,255 characters max</slot>
</div>
<div part="error-message" aria-live="assertive" aria-hidden="false" id="vaadin-text-field-error-0">255 characters max</div>
</div>
</vaadin-text-field>
有人可以调查一下并指出我在这里做错了什么吗? 谢谢, 桑迪
解决方法
如果此答案不能回答您的问题:https://stackoverflow.com/a/61742555/143475
请遵循此过程,以便将来我们可以(以通用方式)添加对此的支持:https://github.com/intuit/karate/tree/develop/examples/ui-test
对于这些事情,我们确实需要社区的帮助,请考虑一下。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。