How to find with Selenium an Element in a dropdown with attribute aria-activedescendant

139 views Asked by At

The webpage I'm automating with Selenium contains a dropdown with three options.The problem I'm facing is that when I click on this dropdown and it expands, in Chrome devtools no change in the HTML is visible so it's not possible for me to define Webelements to interact with the different dropdown options.

When I'm moving my mouse over the three different options the only thing that changes in the HTML is the value of the attribute aria-activedescendant. Here's the HTML snippet.

enter image description here

I tried to directly send the value of the desired option by Selenium sendkeys to the input field and I tried to build a chain of actions like the example below, with the Selenium Action class but nothing works.

public void SelectSpecialist() 
{
    LabelSpecialist.Click();
    Actions actions = new Actions(_webDriver);
    actions.SendKeys(Keys.Down).Build().Perform();//press down arrow key
    actions.SendKeys(Keys.Down).Click().Build().Perform();//press down anothertime and click      
}

In the above example the desired option is highlighted but at the it is not selected, the inputfield stays empty.

However the real problem is that I'm not able to detect the different options of the dropdown as seperated html pieces so I can't define selectors for them.

1

There are 1 answers

0
Frank On

Thanks to Selenium IDE I managed to identify the WebElements of the different dropdown options and the locators, in this case By Id, to use. Never thought before that a record and playback tool could help me this way to write my own test. Thnx Selenium IDE for saving a lot of timeconsuming and boring and frustating moments!