つまり、私はドロップダウンオプションを選択しました。しかし、ここでは、オプションtext
が期待値であると主張したいと思います。私は下にelementSwitcher.element(by.linkText(option)).click()
でドロップダウンオプションの値を選択している分度器 - クリックされた<a>タグのテキストを取得する方法
注:
<div class="btn-group dropdown open" uib-dropdown="">
<ul class="dropdown-menu accounts-dropdown" uib-dropdown-menu="" aria-labelledby="simple-dropdown">
<li ng-repeat="accountChoice in ctrl.accountOptions" class="ng-scope">
<a ng-click="ctrl.selectOption(accountChoice)" class="ng-binding">Assets</a>
</li>
</ul>
</div>
問題は、Iつまり:
this.selectDropdown = function (name, option, uniqueId) {
var elem = element(by.id(uniqueId));
var elementSwitcher = elem.element(by.css("div[uib-dropdown]"));
elementSwitcher.element(by.css("button[uib-dropdown-toggle]")).click();
elementSwitcher.element(by.linkText(option)).click().then(function() {
var el = elementSwitcher.element(by.tagName('a')).getText();
console.log('*** JUST CLICKED. el text = ', el);
});
};
とレンダリングされたHTMLは次のようになります私が期待しているAssets
テキストにアクセスできない、そして私のconsole.log()
は私に言っている:
W/element - more than one element found for locator By(css selector,
a) - the first result will be used
*** JUST CLICKED. el text = ElementFinder {
browser_:
ProtractorBrowser {
controlFlow: [Function],
は再び、私はその後、ドロップダウン要素(a
タグ)をクリックし、クリックされたものと同じa
タグのtext
一部を取得したいと思います。
アドバイスをいただきありがとうございます。
**** UPDATE ****
以下アレックスの答えを1として、私は私の最後のヘルパー関数を投稿:
/**
* Helper function to select an angular-ui dropdown option, and return the <a> link text which was selected.
*
* @param name
* @param option
* @param uniqueId
*
* @returns {Promise} A promise that returns the link text when resolved.
*/
this.selectUibDropDownOption = function (name, option, uniqueId) {
var deferred = protractor.promise.defer();
var elem = element(by.id(uniqueId)); // i.e. by.id('drpAccount')
var elementSwitcher = elem.element(by.css("div[uib-dropdown]"));
elementSwitcher.element(by.css("button[uib-dropdown-toggle]")).click();
// i.e. by.linkText('Liabilities and Equity')
//elementSwitcher.element(by.linkText(option)).click(); // also works, but doesn't get link text
var link = elementSwitcher.element(by.linkText(option));
// Important to first get the text of the <a> tag, then click on the link.
link.getText().then(function (linkText) {
link.click();
deferred.fulfill(linkText);
});
return deferred.promise;
};
とから呼び出し関数です。ここで、私のdescribe/it
が定義されています:
var specItem = it(item.name, function() {
item.search.map(function (srchItem) {
// i.e. { "name": "Account", "option": "Assets", "uniqueId": "drpAccount" },
\t var optionText = pageObjects.selectUibDropDownOption(srchItem.name, srchItem.option, srchItem.uniqueId);
\t
\t optionText.then(function (linkText) {
\t console.log('** Clicked on: ', linkText);
\t expect(srchItem.option).toEqual(linkText);
\t });
});
});
右を。私はgetText()の約束を解決するのを忘れていました。 'linkText'パラメータがコンソールに表示されないので、あなたの更新された方法を試してみましょう。それはちょうど '***ちょうどクリックされたことを言う。 el text = '私のアプローチでは、by.tagName( 'a')は複数の要素を返しています。 –
いくつかの試行錯誤の後、私はあなたの2番目のアプローチである 'link.getText()。then'をどこかに持っています。 –
@ bob.mazzo phew、私はあなたがどこかに行くのを待っていました:)問題の現在の状態は何ですか?ありがとう。 – alecxe