1

Following the other question that I raised recently, could you guys help spot what is wrong with the way how I wrote the "below" friendly locator? Thank you in advance!

Scenario: Get UI - Download
   Given url 'https://test01/v1/doc/env/
   And headers headers1
   When method get
   Then status 200
   * def env = response.url

   Given driver env
   And click('{button}Proceed')
   And click('{span}Start')
   And click('{span}Required - GSA)
   And click('{span}Required - GSB')
   And click('{span}Required - GSC')
   And click('{span}Required - GSD')
   And click('{span}Required - GSE')
   And click('{span}Required - GSF')
   And click('{span}Required - GSG')
   And click('{span}Required - GSH')
   * below('{}Required - GSH').input('karate dsl')

I have a textarea that I would like values to be entered, but the friendly locator "below" is not working for me.

javascript evaluation failed: below('{}Required - GSH').input('karate dsl'), unable to find: {}Required - GSH, BELOW, INPUT

Update: Here's the snippet of the HTML:

Radio button that I need to select first, so the text area will be enabled/required

<div class="doc-tab radio-tab  signing-required       use-olive" id="tab-c6cfbed8-694a-4004-9294-cc0195bab1d0" data-id="c6cfbed8-694a-4004-9294-cc0195bab1d0" data-type="Radio" data-label="FINQ1_66c4593b-7d61-43b5-985f-a22e0909d3dd_b6c1ea40-7291-4ee8-b682-cd770a1bfef8" style="left:61.44px; top:421.76px;">

    <div class="rb">
      <input type="radio" id="tab-form-element-c6cfbed8-694a-4004-9294-cc0195bab1d0" aria-invalid="false" name="FINQ1_66c4593b-7d61-43b5-985f-a22e0909d3dd_b6c1ea40-7291-4ee8-b682-cd770a1bfef8" class="rb_input main-radio-tab-input" value="tab.id" data-qa="radio-tab-c6cfbed8-694a-4004-9294-cc0195bab1d0">
      <label for="tab-form-element-c6cfbed8-694a-4004-9294-cc0195bab1d0" class="rb_label" data-qa="radio-tab-label-c6cfbed8-694a-4004-9294-cc0195bab1d0"><span class="tab-label" style="white-space: nowrap; width: auto;">Required - GSG</span></label>
    </div>
</div>

<div class="doc-tab radio-tab signed signing-required       use-olive" id="tab-d05ca57f-06a7-4f2f-a297-da01dc93290a" data-id="d05ca57f-06a7-4f2f-a297-da01dc93290a" data-type="Radio" data-label="FINQ1_66c4593b-7d61-43b5-985f-a22e0909d3dd_b6c1ea40-7291-4ee8-b682-cd770a1bfef8" style="left:61.44px; top:446.08px;">

    <div class="rb">
      <input type="radio" id="tab-form-element-d05ca57f-06a7-4f2f-a297-da01dc93290a" aria-invalid="false" name="FINQ1_66c4593b-7d61-43b5-985f-a22e0909d3dd_b6c1ea40-7291-4ee8-b682-cd770a1bfef8" class="rb_input main-radio-tab-input" value="tab.id" checked="" data-qa="radio-tab-d05ca57f-06a7-4f2f-a297-da01dc93290a">
      <label for="tab-form-element-d05ca57f-06a7-4f2f-a297-da01dc93290a" class="rb_label" data-qa="radio-tab-label-d05ca57f-06a7-4f2f-a297-da01dc93290a"><span class="tab-label" style="white-space: nowrap; width: auto;">Required - GSH</span></label>
    </div>
</div>

<div class="doc-tab text-tab  signing-required has-tab-error" id="tab-3c020567-3db9-449b-bed5-c44b32a236fa" data-id="3c020567-3db9-449b-bed5-c44b32a236fa" data-type="Text" data-label="FINQues1_1_comments_Text_66c4593b-7d61-43b5-985f-a22e0909d3dd_b6c1ea40-7291-4ee8-b682-cd770a1bfef8" style="left:56.32px; top:503.04px;">

Here's the text area that I would like to locate using the "below" friendly locator.

<div class="doc-tab text-tab  signing-required         has-tab-error" id="tab-3c020567-3db9-449b-bed5-c44b32a236fa" data-id="3c020567-3db9-449b-bed5-c44b32a236fa" data-type="Text" data-label="myQues1_1_comments_Text_66c4593b-7d61-43b5-985f-a22e0909d3dd_b6c1ea40-7291-4ee8-b682-cd770a1bfef8" style="left:56.32px; top:503.04px;">
 
    <div id="tab-sizer-3c020567-3db9-449b-bed5-c44b32a236fa" class="tab-form-element signing-required tab-sizer multiline" style="width: 676px; font-family: &quot;Lucida Console&quot;, &quot;Andale Mono&quot;, Monaco, monospace; font-size: 12.16px; letter-spacing: 0.14px; color: rgb(0, 0, 0); line-height: 14px; text-align: left; height: auto; min-height: auto; white-space: pre-wrap;"></div>
 
    <textarea id="tab-form-element-3c020567-3db9-449b-bed5-c44b32a236fa" aria-invalid="false" title="" data-qa="text-multi-input-tab-3c020567-3db9-449b-bed5-c44b32a236fa" class="main-text-tab-input tab-form-element signing-required " maxlength="450" style="width: 676px; font-family: &quot;Lucida Console&quot;, &quot;Andale Mono&quot;, Monaco, monospace; letter-spacing: 0.14px; color: rgb(0, 0, 0); line-height: 14px; text-align: left; font-size: 12.16px !important; height: 98px;"></textarea>
 
    <label for="tab-form-element-3c020567-3db9-449b-bed5-c44b32a236fa" class="tab-label" style="white-space: nowrap; width: auto;">Required<span class="tab-error-message" aria-live="polite"></span></label>
</div>

Drachir
  • 59
  • 7
  • impossible to answer without seeing your HTML, can you point to a public example like this: https://stackoverflow.com/a/60800181/143475 - or you have to follow this process: https://github.com/intuit/karate/tree/develop/examples/ui-test - but see my answer guess below – Peter Thomas Apr 28 '20 at 11:10
  • @PeterThomas, thank you so much for your prompt response. Really appreciate it. I have updated question with snippet of the HTML because adding .find('textarea') didn't work. – Drachir Apr 28 '20 at 23:43
  • 1
    @PeterThomas, this ```* click('textarea[id=tab-form-element-3c020567-3db9-449b-bed5-c44b32a236fa]').input('karate dsl')``` works for me. – Drachir Apr 29 '20 at 01:47
  • @PeterThomas, The above works for single template only since the text area id is getting generated dynamically for new document. Is there a way that I can use ```
    ``` to locate the object? I tried multiple way using {^} but to no avail.
    – Drachir Apr 29 '20 at 04:43
  • won't simply `* input('.doc-tab textarea', 'karate dsl')` or `.main-text-tab-input` work ? – Peter Thomas Apr 29 '20 at 05:22
  • @PeterThomas, I have 13 of them in the page so I need to uniquely identify each one of them. The prefix of the data-label is something that I can use to uniquely steer them individually by using ```myQues1_1***```, ```myQues1_2***```, and so forth. – Drachir Apr 29 '20 at 05:56
  • ok - can you see my edit. this is an interesting challenge ! – Peter Thomas Apr 29 '20 at 06:39
  • 1
    @PeterThomas, You and KarateDSL rock! I am automating API + UI and the tool is awesome! – Drachir Apr 29 '20 at 07:24

1 Answers1

1

Just a guess, try this:

* below('{}Required - GSH').find('textarea').input('karate dsl')

This is needed if not the "default" input, see docs: https://github.com/intuit/karate/tree/master/karate-core#friendly-locators

EDIT: the following will work for your use-case in version 0.9.6.RC2

  * def list = locateAll('div[data-label]')
  * def condition = function(x){ var label = x.script("_.getAttribute('data-label')"); return label.startsWith('myQues1_2') }
  * def found = karate.filter(list, condition)
  * found[0].locate('textarea').input('karate dsl')

It is a little tricky, but please refer to the docs for each API to understand what is going on.

And I have opened a feature request to make this even easier, feel free to comment there or propose more changes: https://github.com/intuit/karate/issues/1123

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248