I have challenges accessing a value from a dropdown list. The List is created using Bootstrap's dropdown.js
.
I created a custom command in "Nightwatch" with 2 input parameters: "locator" of the dropdown button and the value to be found on the list. The output should be selected value from the dropdown.
Problem: Dropdown gets open but attempts to access values from it generates the error:
TypeError: this.elementIdAttribute is not a function
I've read through all the posts on stack overflow and based on them the syntax is correct. I'm out of ideas.
Under comments is the path to the dropdown element and change the value of li:nth-child(2)
I can select every element on the list.
Below is the code (wrapped in *** is the place that produce the error):
exports.command = function(locator, valueToClick) {
var dropdown;
//locator sample
//.click('#form > div.panel.panel-primary > div.panel-body > div:nth-child(1) > div > div.btn-group.bootstrap-select.form-control.parsley-validated > button')
//.click('#form > div.panel.panel-primary > div.panel-body > div:nth-child(1) > div > div.btn-group.bootstrap-select.form-control.parsley-validated.open > div > ul > li:nth-child(2) > a > span.text')
// cut " > button" from the end
var dropdownElementLocator = locator.slice(0,locator.length-9);
//var openDrop = '#form > div.panel.panel-primary > div.panel-body > div:nth-child(1) > div > div.btn-group.bootstrap-select.form-control.parsley-validated.open > div > ul li a span.text'
var openDrop = dropdownElementLocator + '.open > div > ul > li'
this
.click(locator)
.elements('css selector', openDrop, function(result){
console.log("number of elements = " + result.value.length);
console.log(result);
result.value.forEach(function (element){
console.log(***this.elementIdAttribute***(element.ELEMENT, 'a').value);
});
var position = -1;
var i = 0;
result.value.forEach(function(value){
i++;
var loc = openDrop + ':nth-child(' + i + ') > a > span.text'
})
position = position>-1 ? position : 0;
console.log("final position " + i )
//add ".open > div > ul > li:nth-child(2) > a > span.text"
dropdownElementLocator = dropdownElementLocator + ".open > div > ul > li:nth-child(" + (position+1) + ") > a > span.text";
this.click(dropdownElementLocator);
})
};