簡體   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