我正在使用空手道,并且正在寻找一种方法来在深度跨度中匹配值。
我有这种情况:
...
<form action="#">
<div class="row">
<div class="col-lg-12">
<div class="card shadow mb-4">
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
<div class="card-body">
<p>...</p>
<div class="form-group " style="display: grid; grid-template-rows: auto auto;">
<span>
<label for="title">Title</label>
<input name="title" id="title" class="form-control" placeholder="e.g. My MacBook Key" value="">
</span>
<span class="invalid-feedback">Title is required</span>
</div>
<div class="form-group " style="display: grid; grid-template-rows: auto auto;">
<span>
<label for="key">Key</label>
<textarea name="key" id="key" class="form-control" rows="12" placeholder="Typically starts with "ssh-rsa" or "ssh-ed25519""></textarea>
</span>
<span class="invalid-feedback">Key is required</span>
我需要检查最后一个跨度的值(使用匹配)-最后一行(如果跨度中存在“需要键”)。
我尝试了一些代码变体,但未成功。例如:
* match text('form/div/div/div/div:2/div:2/span:2') == 'Key is required'
或
* match text('{span:2}.invalid-feedback') == 'Key is required'
任何不使用完整xpath的想法如何解决?
谢谢。
有一个非常简单的方法:
* def messages = scriptAll('.invalid-feedback', '_.innerHTML')
* match messages[1] == 'Key is required'