2016-11-28 120 views
3

对于量角器我很陌生,想知道为什么我的按钮在使用selenium webdriver管理器在量角器中运行测试时没有被点击。量角器css选择器无法识别的元素

按钮:

<button class="preview-toggle" icon="add" icon-only="" right="" ng-reflect-router-link="add"></button> 

在镶边时,我使用下面的选择:[纳克 - 反射 - 路由器链路=“添加”]所需的元素被发现。

我量角器,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; 
+0

你不必给'browser.element'。它应该是'element(by.css('[ng-reflect-router-link =“add”]'))' –

回答

0

尝试用按钮,您的前缀属性选择:

element(by.css('button[ng-reflect-router-link=add]')); 
1
element(by.css(".preview-toggle")); 

应该工作

+0

感谢您的回答,我现在能够找到元素。事情是该项目只能在Firefox中找到,而不是在铬。我们需要使用chrome进行测试,因为它对此浏览器是最优化的。即使当我选择全身并在控制台中打印时,我也没有得到任何价值。 有什么建议吗? – remonh87

+0

试着等待。这可能是测试更快,通常我们知道chrome比其他浏览器更快: –

1
var el = element(by.css(".preview-toggle")); 
browser.wait(EC.presenceOf(element(by.css(".preview-toggle"))), 30000).then(function() { 
     browser.wait(EC.visibilityOf(element(by.css(".preview-toggle"))), 30000).then(function() { 
      browser.wait(EC.elementToBeClickable(element(by.css(".preview-toggle"))), 30000).then(function() { 
       el .click() 
}); 
}); 
}); 
+0

奇怪,但在5000 ms超时后收到以下消息: org.openqa.selenium.WebDriverException:元素在点上不可点击(1850年,128年)。其他元素会收到点击: remonh87

+0

好,我们正在一个良好的轨道上。你有一些阻止点击的元素。 –

1

你有一些装载元素,等待成为无形的:

browser.wait(EC.invisibilityOf(element(by.id("loading-app-content"))), 30000).then(function() { 
var el = element(by.css(".preview-toggle")); 
browser.wait(EC.presenceOf(element(by.css(".preview-toggle"))), 30000).then(function() { 
    browser.wait(EC.visibilityOf(element(by.css(".preview-toggle"))), 30000).then(function() { 
     browser.wait(EC.elementToBeClickable(element(by.css(".preview-toggle"))), 30000).then(function() { 
      el .click() 
}); 
}); 
}); 
}); 
0

使用这样的:元素(by.className( “预览切换”));它肯定会工作

0

感谢您的帮助,至少我得到了在Firefox和phantomjs工作的选择器。我用下面的代码,以解决学生选课和组件得到阻止微调:

test = function() { 
var EC = protractor.ExpectedConditions; 
var el= element(by.className("preview-toggle")); 


this.Given(/^I open up the application$/, function (callback) { 

    browser.get('foo.nl').then(callback); 
}); 

this.When(/^I click on add$/, function (callback) { 
    // Write code here that turns the phrase above into concrete actions 

    //this is for waiting until loading is done 
    browser.wait(EC.invisibilityOf(element(by.id("loading-app-content"))), 30000).then(function() { 
     //check if the button is there 
     browser.wait(EC.presenceOf(element(by.css(".preview-toggle"))), 30000).then(function() { 
      //check if the element is visible and clickable then click it 
      browser.wait(EC.visibilityOf(element(by.css(".preview-toggle"))), 30000).then(function() { 
       browser.wait(EC.elementToBeClickable(element(by.css(".preview-toggle"))), 30000).then(function() { 
        el.click().then (callback); 
       }); 
      }); 
     }); 
    }); 

}); 

this.Then(/^I should be the best$/, function (callback) { 
    callback(); 
}); 


}; 
module.exports=test; 

问题是因为硒的webdriver在铬崩溃我铬司机没有找到DOM节点但那是另一个问题应对。 :-)

相关问题