在我最近的一篇文章中,我遇到了一个有关hideen元素的问题(请参阅Here)。从那时起,我已经从铬驱动器转向phantomjs进行无头测试。当使用protractorjs和phantomjs时选择隐藏元素
我的问题是这样的。
由于移动选择隐藏元素导致误差下面,
UnknownError: Error Message => ''undefined' is not a function (evaluating 'arguments[0].click()')'
在铬(webdriver的)运行是精细和所有测试通过但phantomjs似乎不喜欢这种方法。是否有另一种方法可以在测试中使用phantomjs
和protractorjs
运行此问题。
编辑 下面的测试是什么,我有问题
it('should redirect to addresses', function() {
var hiddenWebElement = ptor.driver.findElement(by.css('ul#myaccount li:nth-child(2) a'));
ptor.driver.executeScript("arguments[0].click()",hiddenWebElement).then(function() {
expect(ptor.driver.getCurrentUrl()).toContain('#/addresses');
});
}, 15000);
我的配置文件是
// An example configuration file.
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
baseUrl: 'http://localhost:52254',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'phantomjs'
},
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: [
'Scenarios/account_spec.js',
'Scenarios/add_address_spec.js'
],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
}
};
要注意的一点是,此上方运行所有测试预计下一个当试图找到元件时再次存在问题
it('should redirect to login', function() {
ptor.driver.findElement(by.id('headerLoginBtn')).click().then(function() {
expect(ptor.driver.getCurrentUrl()).toContain('/Account/Login');
});
}, 15000);
其中抛出元素的异常是不可见的。此外,我在这种情况下的测试使用ptor.driver,因为页面包含c#ASP.NET代码。
你能分享更多的测试代码吗?这个错误在你的测试中看起来像是错误的,而不是来自webdriver的错误。 – Jmr
出于兴趣,您为什么要点击隐藏的元素?量角器测试旨在复制用户行为,并且用户无法单击隐藏的元素。 (我并不是说这些工具不能用于替代目的) – Dan
我有一个按钮可以激活下拉菜单,直到按钮悬停在菜单上才会出现。因此需要选择隐藏的元素。 –