这个问题在这里已经有了答案:
protractor cannot locate element with css on ng-click element
(1 个回答)
4年前关闭。
我对 Protractor 很陌生,想知道为什么在使用 selenium webdriver manager 在 Protractor 中运行测试时我的按钮没有被点击。
按钮:
<button class="preview-toggle" icon="add" icon-only="" right="" ng-reflect-router-link="add"></button>
在 chrome 中,当我使用以下选择器时: [ng-reflect-router-link="add"] 找到了所需的元素。
我的 Protractor conf.js:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub', // This is targetting my local running instance of the selenium webdriver
specs: [
'./features/**/*.feature'
],
capabilities: {
browserName: 'chrome'
},
framework: 'custom', //We need this line to use the cucumber framework
frameworkPath: require.resolve('protractor-cucumber-framework'), // actual framework
cucumberOpts: {
format: 'pretty',
require: './features/step_definitions/**/*.js' // This is where we'll be writing our actual tests
},
useAllAngular2AppRoots: true
};
我的要素类是一个简单的类
Feature: Cool_feature
Scenario: I do something awesome
Given I open up the application
When I click on add
Then I should be the best
我的 test.js 类
test = function() {
this.Given(/^I open up the application$/, function (callback) {
browser.get('foo.com').then(callback);
});
this.When(/^I click on add$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
browser.element(by.css('[ng-reflect-router-link="add"]')).click().then(callback);
});
this.Then(/^I should be the best"$/, function (callback) {
});
};
module.exports=test;
最佳答案
element(by.css(".preview-toggle"));
应该管用
关于angularjs - Protractor css选择器无法识别元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40853892/