How to select option in drop down protractorjs e2e tests
I had a similar problem, and eventually wrote a helper function that selects dropdown values.
I eventually decided that I was fine selecting by option number, and therefore wrote a method that takes an element and the optionNumber, and selects that optionNumber. If the optionNumber is null it selects nothing (leaving the dropdown unselected).
var selectDropdownbyNum = function ( element, optionNum ) {
if (optionNum){
var options = element.all(by.tagName('option'))
.then(function(options){
options[optionNum].click();
});
}
};
I wrote a blog post if you want more detail, it also covers verifying the text of the selected option in a dropdown: http://technpol.wordpress.com/2013/12/01/protractor-and-dropdowns-validation/
How to select a drop down using protractor?
Try:
var Tiers = element(by.xpath(dropDownValue));
Tiers.click();
selectDropdownbyNum(element, optionNum) {
if (optionNum) {
element.all(by.tagName('option')).then(function(options) {
options[optionNum].click();
});
}
}
selectDropdownbyNum(Tiers,4)
Note:
avoid using Xpath example use :
element(by.css('select[formcontrolname="any value according to situation"]'));
How to select option in drop down protractorjs e2e tests
I had a similar problem, and eventually wrote a helper function that selects dropdown values.
I eventually decided that I was fine selecting by option number, and therefore wrote a method that takes an element and the optionNumber, and selects that optionNumber. If the optionNumber is null it selects nothing (leaving the dropdown unselected).
var selectDropdownbyNum = function ( element, optionNum ) {
if (optionNum){
var options = element.all(by.tagName('option'))
.then(function(options){
options[optionNum].click();
});
}
};
I wrote a blog post if you want more detail, it also covers verifying the text of the selected option in a dropdown: http://technpol.wordpress.com/2013/12/01/protractor-and-dropdowns-validation/
How to select option in drop down protractorjs e2e tests
I had a similar problem, and eventually wrote a helper function that selects dropdown values.
I eventually decided that I was fine selecting by option number, and therefore wrote a method that takes an element and the optionNumber, and selects that optionNumber. If the optionNumber is null it selects nothing (leaving the dropdown unselected).
var selectDropdownbyNum = function ( element, optionNum ) {
if (optionNum){
var options = element.all(by.tagName('option'))
.then(function(options){
options[optionNum].click();
});
}
};
I wrote a blog post if you want more detail, it also covers verifying the text of the selected option in a dropdown: http://technpol.wordpress.com/2013/12/01/protractor-and-dropdowns-validation/
protractor select values from drop down implemented using mat-select
This is how I solved it. First I had to click the dropdown and then another click for selecting the value.
element(by.tagName('mat-toolbar')).element(by.tagName('mat-select')).click();
element(by.cssContainingText('mat-option .mat-option-text', 'Delta')).click();
browser.waitForAngular();
Thanks for your guidance guys. Appreciate it.
Select a particular option in Protractor
Found the perfect answer.
element.all(by.css('cssSelector of the dropdown')).each(function (eachElement, index)
{
eachElement.click();// select the <select>
browser.driver.sleep(500);// wait for the renderings to take effect
element(by.css('cssSelector of option want to select')).click();// select the first md-option
browser.driver.sleep(500);// wait for the renderings to take effect
});
This works like calm :)
Related Topics
What Is Returned from a Constructor
How to Execute Promises Sequentially, Passing the Parameters from an Array
Caching a Promise Object in Angularjs Service
Recursive Matching with Regular Expressions in JavaScript
Variable Scope in D3 JavaScript
Chrome Extension - Sendresponse Not Waiting for Async Function
Why Does This JavaScript Code Print "Undefined" on the Console
Turning Off Eslint Rule for a Specific Line
Print Content of JavaScript Object
What's the Best Way to Break from Nested Loops in JavaScript
Calling a JavaScript Function Named in a Variable
What Do Curly Braces Inside of Function Parameter Lists Do in Es6
How to Capture Response of Form.Submit
Fetch: Reject Promise and Catch the Error If Status Is Not Ok
How to Check in JavaScript If One Element Is Contained Within Another