问题描述
在我最近提出另一个问题之后,你们能帮我找出我编写下方"友好定位符的方式有什么问题吗?预先谢谢你!
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
更新:这是HTML的代码段:
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: "Lucida Console", "Andale Mono", 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: "Lucida Console", "Andale Mono", 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>
推荐答案
只是一个猜测,请尝试以下方法:
Just a guess, try this:
* below('{}Required - GSH').find('textarea').input('karate dsl')
如果不是默认" input
,这是必需的,请参阅文档: https://github.com/intuit/karate/tree/master/karate-core#friendly-locators
This is needed if not the "default" input
, see docs: https://github.com/intuit/karate/tree/master/karate-core#friendly-locators
以下内容将在0.9.6.RC2版本中适用于您的用例
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')
这有点棘手,但是请参阅每个API的文档以了解发生了什么.
It is a little tricky, but please refer to the docs for each API to understand what is going on.
我已经打开了一个功能请求,以使其变得更加容易,可以在此处发表评论或提出更多更改: https://github.com/intuit/karate/issues/1123
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
这篇关于KarateDSL UI测试-友好定位器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!