How to get the selected dropdown text



Hi. Can I know how can I get the text ‘Afghanistan’ from this dropdown. I have try with getText but it return me the list of dropdown . While, getAttribute(findTestObject(‘object name’), ‘value’) return me ‘AF’.

1 Like

To investigate, start DevTools to review your HTML; either hit the F12 key, click on “Open DevTools”, then use either CTRL + SHIFT + C or click on the first icon within DevTools that looks like a rectangle with a pointer moving into it. Then move your mouse pointer to an element. Click on the element to have the HTML display that element. Or you can hover over the element to have the information displayed.
Another method that may work, you can right click on an element and choose, Inspect. Then, right click on the element again and choose Inspect again to move the HTML right to your element.

If the tag associated with the drop-down object is a <select>, then there are methods to get the appropriate option, such as: selectOptionByLabel(), selectOptionByValue() and selectOptionByIndex(). Unfortunately, since you don’t show us the HTML of your drop-down, there is really no way for us to know if you have a <select> tag or a bunch of <div> tags with <input> tags for a more complicated application.

1 Like