0

要素の仕組みを誤解していると思います..

HTML コード:

<div id="div-item">
    <a href="#">A link</a>
    <form>
        <div>
            <select>
                <option>1</option>
                <option>2</option>
            </select>
        </div>
    </form>
</div>

私がこれを行うとき:

element(by.tagName('select')).all(by.tagName('option')).count();

これは私に2を与えます、これは正しいです

私がこれを行うとき:

element(by.id('div-item')).element(by.tagName('select')).all(by.tagName('option')).count();

これは私に0を与えます。連鎖要素はサブ要素を見つけると思いました。これは正しくありませんか?ページ全体ではなく、この div 内でのみ .all(by.tagName('option')) を制限するにはどうすればよいですか?

これは xeditable ライブラリです。私のHTMLコードは次のとおりです。

<div id="div-item" class="col-xs-3">
    <a id="xeditable-link" href="#" ng-if="canEdit"
       editable-select="user_id"
       e-ng-options="user.id as user.name for user in users"
       onbeforesave="updateProfile({user_id: $data})">
       {{ showNameFromID(user_id) || 'none'}}
    </a>
</div>

しかし、これは大量の HTML コードを生成します。それは次のようなものです:

<div id="div-item" class="col-xs-3">
    <a id="xeditable-link" href="#" ng-if="canEdit"
       editable-select="user_id"
       e-ng-options="user.id as user.name for user in users"
       onbeforesave="updateProfile({user_id: $data})">
       {{ showNameFromID(user_id) || 'none'}}
    </a>
    <form ...>
        <div class="xeditable-controle..." ...blah blah>
            <select ...ng-options="..." blah blah>
                <option>1</option>
                <option>2</option>
            </select>
            <span> ...the buttons... </span>
        </div>
    </form>
</div>

私のテスト仕様:

it('should pass ...', function() {
    element(by.id('xeditable-link')).click(); // Click the link to bring up xeditable
    element(by.tagName('select')).click();    // Click the select to bring up the popup
    var allOptions = element(by.id('div-item')).element(by.tagName('select')).all(by.tagName('option'));
    expect(allOptions.count()).toBe(2);
    for (var i = 0; i < 2; ++i) {
        expect(allOptions.get(i).getText()).toBe(testText[i]);
    }
});

期待ステートメントは両方とも失敗します。count は 2 ではなく 0 であり、「NoSuchElementError: ロケーターを使用して要素が見つかりません: By.tagName("select")」

4

2 に答える 2

1

単一の CSS ロケーターを試す

$$('#div-item select [option]').count()
// The same as
element.all(by.css('#div-item select [option]')).count()
于 2015-01-07T15:04:46.790 に答える
0

別の.htmlファイルに「div-item」があったことがわかりました。AngularJS は単一ページのアプリケーションであるため、私が望んでいたアプリケーションではなく、そのアプリケーションを選択していました。

于 2015-01-07T15:34:02.457 に答える