[英]ShadowRoot dom elements access issue in Karate UI
I am trying to access ShadowRoot dom tree elements, but the problem I face is I cannot use the Specific html element to call on .ShadowRoot, as that element is dynamic (see below html snippet id="vaadin-text-field-error-0). So only way I can do is by accessing the class .vaadin-text-field-container which is one level up. Basically, below is the html code snippet where it returns an "error message = 255 characters max" and in my KarateUI test I am trying to assert that error message. So far I tried the below options based on previous forum queries I read, but no luck I could never access the right element that returns the text "255 characters max" to do the assertion:我正在尝试访问 ShadowRoot dom 树元素,但我面临的问题是我无法使用特定的 html 元素来调用 .ShadowRoot,因为该元素是动态的(请参阅下面的 html 代码段 id="vaadin-text-field-error- 0). 所以我唯一能做的就是访问一个级别的 .vaadin-text-field-container 类。基本上,下面是 html 代码片段,它返回一个“错误消息 = 255 个字符最大”和我的 KarateUI 测试我试图断言该错误消息。到目前为止,我根据我阅读的以前的论坛查询尝试了以下选项,但没有运气我永远无法访问返回文本“最大 255 个字符”的正确元素来进行断言:
Try 1:尝试 1:
* def test = script('.vaadin-text-field-container', '_.innerHTML')
* print "Error Message is" + test
Output :输出 :
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}"}
Try 2:尝试2:
* def test = script('//*[@id="vaadin-text-field-error-0"]', '_.innerHTML')
* print 'Error Message is :' + test
Output:输出:
evaluation (js) failed: script('//*[@id="vaadin-text-field-error-0"]', '_.innerHTML'), 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) })(), error: {"type":"object","subtype":"error","className":"SyntaxError","description":"SyntaxError: missing ) after argument list","objectId":"{\"injectedScriptId\":3,\"id\":3}"}
Try 3:尝试3:
* match text('#vaadin-text-field-error-0') == '255 characters max'
Output:输出:
evaluation (js) failed: text('#vaadin-text-field-error-0'), js eval failed twice:document.querySelector("#vaadin-text-field-error-0")['textContent'], error: {"type":"object","subtype":"error","className":"TypeError","description":"TypeError: Cannot read property 'textContent' of null\n at <anonymous>:1:53","objectId":"{\"injectedScriptId\":3,\"id\":3}"}
HTML code snippet here:这里的 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>
Can someone please look into this & point me what I am doing wrong here?有人可以看看这个并指出我在这里做错了什么吗? Thanks, Sandy谢谢,桑迪
If this answer does not answer your question: https://stackoverflow.com/a/61742555/143475如果此答案不能回答您的问题: https : //stackoverflow.com/a/61742555/143475
Please follow this process, so that we can work on adding support for this (in a generic way) in the future: https://github.com/intuit/karate/tree/develop/examples/ui-test请遵循此流程,以便我们将来可以(以通用方式)添加对此的支持: https : //github.com/intuit/karate/tree/develop/examples/ui-test
We really need community help for some of these things, do consider it.我们真的需要社区帮助来解决其中的一些问题,请考虑一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.