我正在尝试从jq小部件的下拉列表中选择一个复选框。现在,当元素在视图中时,代码可以工作,但不是。我知道我们需要滚动到元素以便量角器能够找到它。我尝试在这里使用executeScript和scrollIntoView但是无法滚动到元素。我也尝试了其他一些东西。请帮帮我。
// conf.js
exports.config = {
directConnect: true,
framework: 'jasmine',
specs: ['jq.spec.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeOutInterval: 30000000
},
}
我的jq.spec.js:
describe('should check jq widgets', function() {
it("should check the scrolling is proper",function() {
browser.ignoreSynchronization = true;
browser.get('http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxdropdownlist/checkboxes.htm?arctic');
browser.wait(protractor.ExpectedConditions.visibilityOf($('#dropdownlistContentjqxWidget')),500000,'dropdown did not display');
$('#dropdownlistContentjqxWidget').click().then(function(){
$('#listitem0innerListBoxjqxWidget>div').click();
scrollIntoView(element(by.xpath("//span[text()='Francisco Chang']/parent::div/div")));
element(by.xpath("//span[text()='Francisco Chang']/parent::div/div")).click();
browser.sleep(10000);
});
});
});
var scrollIntoView = function(element){
browser.executeScript(function(element) {
element.scrollIntoView();
}, element.getWebElement());
});
};
//错误:
Failures:
1) should check jq widgets should chech the scrolling is proper
Message:
Failed: No element found using locator: By(xpath, //span[text()='Francisco Chang']/parent::div/div)
答案 0 :(得分:0)
我建议您更改scrollIntoView
功能。 jasmine的包装器将所有内容解析为控制流,但由于它返回void,我很确定这会开始执行scrollIntoView
并立即返回(在browser.executeScript
添加到控制流之前。然后你尝试点击元素而不将其滚动到视图中。另外为了完整性我添加了一个JSDoc:
/**
* Scroll to find some element in the view
* @param {ElementFinder} element the located element of interest
* @returns {webdriver.promise.Promise} returns a webdriver promise
*/
var scrollIntoView = function(element){
return browser.executeScript(function(element) {
element.scrollIntoView();
}, element.getWebElement());
});
};