繁体   English   中英

空手道 UI 中的 ShadowRoot dom 元素访问问题

[英]ShadowRoot dom elements access issue in Karate UI

我正在尝试访问 ShadowRoot dom 树元素,但我面临的问题是我无法使用特定的 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"]', '_.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}"}

尝试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'], 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 代码片段:

<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

我们真的需要社区帮助来解决其中的一些问题,请考虑一下。

暂无
暂无

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

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