In my project I have a drop down list, from where I am selecting an option based on the text. My objective is to test once the option is selected, the text that is being shown in the dropbox (like the picture below), is matching with my input value or not.
My code is as follows:
this.selectDropdownByText = async function(container, inputText){
await helpers.clickWhenClickable(element(by.cssContainingText('option',inputText)), 5000, "the selected option is not clickable");
await helpers.clickWhenClickable(CL.Save_Button_BottomPanel,10000);
await sync.waitUntilElementVisible(await CL.Save_success_Massage, 10000);
await sync.waitUntilElementInVisible(await CL.Save_success_Massage, 10000);
await helpers.waitForElementVisibility(container);
return await container.getSelection().getText();
There is no problem in the codes until we reach the return statement. However, the return statement returns error when I try container.getSelection().getText()
. The error is TypeError: container.getSelection is not a function
On the other hand, if I try container.getText()
, it returns all the options of the drop list.
Is there any way to accomplish that?
The html code is :
<select _ngcontent-c11="" class="form-control ng-touched ng-dirty ng-valid" formcontrolname="dcbsId"
id="directClassBased">
<!---->
<!---->
<option _ngcontent-c11="" value="1: 54756697-0CC6-45A2-B857-E96E132D46B0" class="ng-star-inserted">HS Com A</option>
<option _ngcontent-c11="" value="2: FA377EE4-66C4-46ED-992D-8D17A6756586" class="ng-star-inserted">HS Com B</option>
<option _ngcontent-c11="" value="3: 7BA46C9C-6150-4E5D-8FD0-270D6387D772" class="ng-star-inserted">HS Com C</option>
.....
.....
<option _ngcontent-c11="" value="12: 08FD1A93-6507-4ABB-9420-DD2E62F9562C" class="ng-star-inserted">CL TRC</option>