vashi test
vashi test

Reputation: 1

New Relic selecting the first available drop down option from menu

I am stuck on this and hope you can point me in the right direction.

I am using new relic monitoring tool and need to create a monitoring test of the typical E-commerce user journey, search, select a product, select a size and then add to bag.

The problem I get is, some product sizes go out of stock and that breaks my test. I have the following code that allows me to pick a specific product, but does anyone know how to select the first available option?

Any help would be appreciated.

Thanks

//Example: Selecting an option and retrieving the selected label/value
var By = $driver.By,
selectbox;
// ----------------------------------------------------------------------------- //
// Helper function that returns the first selected option given a select element
function findSelected(select) {
var d = $driver.promise.defer();
select.findElements(By.tagName('option')).then(function (options) {
options.forEach(function(option) {
option.isSelected().then(function(selected) {
if (selected) {
d.fulfill(option);
}
});
});
});
return d.promise;
}
// ----------------------------------------------------------------------------- //
// Load the page
$browser.get("http://www.w3schools.com/html/tryit.asp?filename=tryhtml_select2").then(function(){
  // Focus the iframe
  $browser.switchTo().frame("iframeResult");
  // Click on select
    return $browser.waitForAndFindElement(By.name("cars"), 15000).then(function(elem) {
    selectbox = elem;
    selectbox.click();
  });
}).then(function() {
  // Select an option
    return selectbox.findElement(By.css("option[value='audi']")).click();
})

Upvotes: 0

Views: 136

Answers (1)

vashi test
vashi test

Reputation: 1

I was able to get around this by using sendkeys down arrow and enter, if that helps anybody.

Upvotes: 0

Related Questions