Search code examples
typescripttestingprotractordropdown

How can I select any item in this dropdown menu using protractor testing?


I've looked online for this but I could only find solutions for basic dropdowns. My dropdown looks like this:

<p-dropdown [options]="uyrukList" 
    id="uyruk" name="uyruk"  class="requried-radius"
    #uyrukInput="ngModel" [required]="true"
    [autoDisplayFirst]="false" [(ngModel)]="uyruk" optionLabel="ad">
</p-dropdown>

I've tried this:

const select = element(by.id('uyruk'));
select.$('value=myRandomItem').click();

but it didn't work.

Is there a way I can select any items in this dropdown menu using protractor? It does not matter to me which item it is.


Solution

  • I've tried to access my dropdown elements using their tagName and it worked for me.

    element.all(by.id('uyruk')).click();
    browser.sleep(500);
    const list = element.all(by.tagName('p-dropdownitem'));
    list.first().click();
    

    In order to access any element with its index:

    list.get(index).click();