如何点击相同内容?
我尝试了以下代码:
describe ('angularjs homepage', function() {
browser.get('http://angular.github.io/peepcode-tunes/public/');
element(by.css('[ng-click="player.playlist.add(album)"]')).click();
});
不幸的是,它不起作用。 请帮忙
最佳答案
您无法单击它们,因为它们都具有相同的类和属性。 在这些情况下,您有 2 个选择:
1)您可以直接使用CSS的nth child
概念。
describe ('angularjs homepage', function() {
browser.get('http://angular.github.io/peepcode-tunes/public/');
element(by.css('#container > section > ul > li:nth-child(1) > button')).click(); // it will click the first "+" button
element(by.css('#container > section > ul > li:nth-child(2) > button')).click(); // it will click the second "+" button
});
2)您可以按照@noor在上面的答案中建议的那样使用索引访问它们:
describe ('angularjs homepage', function() {
browser.get('http://angular.github.io/peepcode-tunes/public/');
element.all(by.css('.queue.add')).get(0).click(); // it will click the first "+" button
element.all(by.css('.queue.add')).get(1).click(); // it will click the second "+" button
});
我测试了一下,两个都有效!如果您遇到问题,请告诉我!
关于javascript - 如何在 Protractor 中单击没有文本的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38496404/