Radim Bukovský
Radim Bukovský

Reputation: 357

Karate - how to match test in deeply placed span tag

I am using Karate and I am finding the way how to match value in deeply placed span.

I have this case:

...
<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 &quot;ssh-rsa&quot; or &quot;ssh-ed25519&quot;"></textarea> 
               </span>
               <span class="invalid-feedback">Key is required</span>

I need to check value of last span (using match) - last line (if "Key is required" is present in span).

I have tried some code variations but I was not successful. E.g.:

* match text('form/div/div/div/div:2/div:2/span:2') == 'Key is required'

or

* match text('{span:2}.invalid-feedback') == 'Key is required'

Any idea how to solve it without using full xpath?

Thank you.

Upvotes: 1

Views: 418

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58088

There is a very easy way to do this:

* def messages = scriptAll('.invalid-feedback', '_.innerHTML')
* match messages[1] == 'Key is required'

Upvotes: 1

Related Questions