Reputation: 445
I'm trying to select an option from a dropdown using Selenium2/WebDriver. I have the following code:
clickCss: function(selector, timeout, dontMoveAfter, finalKey) {
var browser = this.browser;
timeout = timeout || 10000;
var element;
return function(done) {
async.waterfall([
function(cb) {
browser.waitForVisibleByCssSelector(selector, timeout, cb);
},
function(cb) {
browser.elementByCssSelector(selector, cb);
},
function(el, cb) {
element = el;
element.click(cb);
},
function(cb) {
if (dontMoveAfter) {
cb();
} else {
browser.moveTo(element, 0, -50, cb);
}
},
function(cb) {
if (finalKey) {
browser.keys(wd.SPECIAL_KEYS[finalKey], cb);
} else {
cb();
}
},
], done);
};
},
changeAndVerifyStatus: function(){
var w = this;
return function(done){
async.waterfall([
w.clickCss(dropdownSelector,null,true),
w.clickCss(optionSelector,null,true),
], done);
};
},
As you can see I'm just clicking on the dropdown selector and then clicking on the option selector. The results are that it successfully clicks on the dropdown so that a list of options are displayed and then I can see the option that I want to be clicked is highlighted, but it appears that it didn't actually click on it because the javascript action that happens when the dropdown is changed is never fired. I've tried multiple approaches but nothing seems to want to change the dropdown. Any thoughts?
Upvotes: 1
Views: 1478
Reputation: 1059
Try skipping the step of clicking on the select box, go straight to clicking on the option (even though it doesn't appear visible to the human eye). I'm not quite sure why this works, but this question has been asked many times over and this seems to be the easy, browser independent solution.
Upvotes: 1