我在使用量角器5.2.0(节点8.4.0,角度1.5)在ng-repeat循环中定位元素时遇到问题。 UI代码如下所示:
<tr ng-repeat-start="app in appsData.result" class="bordered">
<td>
<md-button id="{{app.name}}" class="md-raised primary" ng-click="appAction('configure', app)">
Configure and Run
</md-button>
</td>
</tr>
<tr ng-repeat-end ng-show="expanded" ng-class="{'highlighted': expanded}">
..... 我试过了
var rows = element.all(by.repeater("app in appsData.result"));
rows.first().element(by.tagName("button")).getText().then(function(text){
console.log("Text: "+text);
});
但是我得到了
[12:24:40] E / launcher - NoSuchElementError:索引越界。试 访问索引处的元素:0,但只有0个元素 匹配定位器by.repeater(“apps in appsData.result”)
(我也试过tagName = md-button)
我做了一个browser.getPageSource() 但我只看到了
<tbody>
<!-- ngRepeat: app in appsData.result -->
</tbody>
我对量角器很新,任何帮助都会非常感谢!
我的量角器配置文件如下所示:
exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
getPageTimeout: 600000,
allScriptsTimeout: 5000000,
framework: 'custom',
// path relative to the current config file
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
browserName: 'chrome',
'chromeOptions': {
args: ['--no-sandbox', 'headless']
}
},
// Spec patterns are relative to this directory.
specs: [
'features/*.feature'
],
baseURL: 'http://localhost:8080/',
cucumberOpts: {
require: 'features/step_definitions/*.js',
tags: false,
format: 'pretty',
profile: false,
'no-source': true
}
};
答案 0 :(得分:0)
如果班级=&#34;有界&#34;是独一无二的,您可以尝试:
var rows = element.all(by.css('[class="bordered"]'));
rows.first().element(by.css('md-button')).getText().then(function(text){
console.log("Text: "+text);
});
希望有所帮助
答案 1 :(得分:0)
试试这个:
var rows = element.all(by.css('[class="bordered"]'));
rows.first().element(by.css('md-raised.primary')).getText().then(function(text){
console.log("Text: "+text);
});
如果这不起作用,您可以通过xpath或类名选择:
element(by.className("md-raised primary"))