[英]How to select option from dropdown in selenium (NodeJs)
I want to write a script for testing dropdown inside the webpage.我想编写一个脚本来测试网页内的下拉菜单。 But, I was unable to do so in selenium using Nodejs.
但是,我无法使用 Nodejs 在 selenium 中这样做。 Is there any method to test dropdown in selenium(NodeJs).
有什么方法可以测试 selenium(NodeJs)中的下拉菜单。
Thanks in advance提前致谢
You can create a select class like this and then use method based on your selection.您可以像这样创建 select class,然后根据您的选择使用方法。
var SelectWrapper = function(selector) {
this.webElement = element(selector);
};
SelectWrapper.prototype.getOptions = function() {
return this.webElement.all(by.tagName('option'));
};
SelectWrapper.prototype.getSelectedOptions = function() {
return this.webElement.all(by.css('option[selected="selected"]'));
};
SelectWrapper.prototype.selectByValue = function(value) {
return this.webElement.all(by.css('option[value="' + value + '"]')).click();
};
SelectWrapper.prototype.selectByPartialText = function(text) {
return this.webElement.all(by.cssContainingText('option', text)).click();
};
SelectWrapper.prototype.selectByText = function(text) {
return this.webElement.all(by.xpath('option[.="' + text + '"]')).click();
};
module.exports = SelectWrapper;
Usage in test class测试中的用法 class
var SelectWrapper = require('./select-wrapper.js');
var mySelect = new SelectWrapper(by.id("validSelectTagID"));
describe("Select Wrapper",function(){
it("Handling the dropdown list",function(){
browser.get("http://validURL");
mySelect.selectByText("TextinDrop");
mySelect.selectByValue("ValueInDrop");
}) ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.