elementIdText API breaks in Version 2.x.x while selecting a value from list of dropdown values #3430
-
Problem : One has to use selenium 4 hard coded string "element-6066-11e4-a52e-4f735466cecf" to click on element by ID *********** Working code NW v 1.7.11 ********************************** this.elements(
dropDownOptionsWebElement.locateStrategy,
dropDownOptionsWebElement.__selector,
options => {
options.value.forEach(v => {
this.elementIdText(v.ELEMENT, result => {
if (result.value === dropDownOptionToSelect) {
this.elementIdClick(v.ELEMENT, () => { console.log(`Selected the ${dropDownWebElement} option: ${dropDownOptionToSelect}`) });
}
});
});
}
);
done();
}); **********Working code NW v2.3.0 and above ******************************** this.elements(
dropDownOptionsWebElement.locateStrategy,
dropDownOptionsWebElement.__selector,
options => {
for(let i = 0; i < options.value.length; i++) {
debugger
this.elementIdText(options.value[i]["element-6066-11e4-a52e-4f735466cecf"], result => {
if (result.value === dropDownOptionToSelect) {
debugger
this.elementIdClick(options.value[i]["element-6066-11e4-a52e-4f735466cecf"]);
i = options.value.length;
}
});
}
});
done();
}); |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 1 reply
-
v.ELEMENT is getting replaced with options.value[i]["element-6066-11e4-a52e-4f735466cecf"] |
Beta Was this translation helpful? Give feedback.
-
Hey @suraj007118 Thanks for raising this. I think you can use |
Beta Was this translation helpful? Give feedback.
-
I need to get element text that is the reason I had to use elementIdText , will element.getId() help me getting text? |
Beta Was this translation helpful? Give feedback.
-
or you mean use it like:
|
Beta Was this translation helpful? Give feedback.
-
It did not work, got below error: |
Beta Was this translation helpful? Give feedback.
-
@suraj007118 you can try using it('find elements', function() {
browser.navigateTo('https://nightwatchjs.org')
.findElements('css selector', 'div', result => {
result.value.forEach(v => console.log(v.getId()));
});
}); |
Beta Was this translation helpful? Give feedback.
@suraj007118 you can try using
findElements
instead ofelements
command and thenoptions.value[i].getId()
will work fine. Here is an example test: