After dropdown is expended how can I select an option from the dropdown which is in span

image of the expanded dropdown https://prnt.sc/k-rFIUa6Ixeo


<span class="ant-select-selection-item" title="Mrs.">Mrs.</span>

C# code where dropdown is expended

WebElement dropDown = (WebElement)Driver.Instance.FindElement(By.XPath("//*[@id=\"root\"]/main/section/form/div/div[1]/div[1]/div[1]/div/div/div"));

Note that title is changing in span element after another option is selected so if we select first option title is Mr.

<span class="ant-select-selection-item" title="Mr.">Mr.</span>

short gif for better visual: https://gyazo.com/8093ced6107599ee7540490d4fba0cc2

Also hovering over dropdown options in the hmtl code above aria-activedescendant property is changing so for the option "MR" property is "rc_select_0_list_0", for option "Mrs" property is "rc_select_0_list_2" and so on,

for more details here is short gif https://gyazo.com/827fc0c4e1265b842301c87da6539e0c

1 Answer 1


While developing automation frameworks in test automation services company, such scenarios are very common and can be automated in number of ways. One of the best approaches that we use especially for this scenario is by creating dynamic locators - As mentioned in your case to select a value from drop down, utilize text instead of title in your xpath as mentioned below -

String str = "MR." //span[text()="+str+"]

Case 2 - Xpath using title attribute - //span[contains(@title, "Mr")]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.