mahesh nani mahesh nani - 2 months ago 16
Node.js Question

Selenium get all options from drop down in node.js

How can I get all options from drop down using selenium with node.js

below is my code:

var dropdown = driver.findElement({xpath: '//*[@name="dropdownname"]'});


from above

var options = dropdown.findElements({tagName: 'option'});


how can i get all options and do foreach in node.js or print options values using node.js.

Thanks in advance.

Answer
driver.findElement({xpath: '//*[@name="dropdownnamewithoptions"]'}).then(function(webElement) {
                    webElement.findElements(By.tagName('option')).then(function(optionArray){
                        if(optionArray.length > 1){
                                  optionArray[0].getAttribute('value').then(function(optionValue) {
                 });
                        }
                    });
                 }, function(err) {
                });