# How print a selected item in drop-down

**URL:** <https://forum.katalon.com/t/how-print-a-selected-item-in-drop-down/49450>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [November 22, 2020, 9:25am UTC](https://forum.katalon.com/t/how-print-a-selected-item-in-drop-down/49450 "2020-11-22T09:25:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![xupacabra](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/xupacabra/32/15043_2.png) [@xupacabra](https://forum.katalon.com/u/xupacabra)\
**Post date:** [November 22, 2020, 9:25am UTC](https://forum.katalon.com/t/how-print-a-selected-item-in-drop-down/49450/1 "2020-11-22T09:25:36Z")

</div>

I swear I spent the last six hours on the forum, looking for the answer to something so simple.

How to capture the text that is appearing in the drop-down (selected)?

---

<div class="post-metadata">

**Author:** ![Timo\_Kuisma1](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/timo_kuisma1/32/16103_2.png) [@Timo\_Kuisma1](https://forum.katalon.com/u/Timo_Kuisma1)\
**Post date:** [November 22, 2020, 10:14am UTC](https://forum.katalon.com/t/how-print-a-selected-item-in-drop-down/49450/2 "2020-11-22T10:14:06Z")

</div>

hi,

you can use two different methods to get text value from UI

> **[\[WebUI\] Get Text](https://docs.katalon.com/katalon-studio/docs/webui-get-text.html#example-)**
>
> Description   Get the visible (i.e. not hidden by CSS) inner text of the web element, including sub-elements, without any leading or trailing whitespace. Parameters   Param Param Type Mandatory Description...

  
or  

> **[\[WebUI\] Get Attribute](https://docs.katalon.com/katalon-studio/docs/webui-get-attribute.html#description)**
>
> Description Get the attribute of a web element. Parameters Param Param Type Mandatory Description to TestObject Required Represent a web element attribute String Required Name of the attribute flowControl FailureHandling...

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [November 23, 2020, 7:53pm UTC](https://forum.katalon.com/t/how-print-a-selected-item-in-drop-down/49450/3 "2020-11-23T19:53:15Z")

</div>

@xupacabra If it is still in the drop-down state, and you need to do something with the text, then you need something like:

```auto
import org.openqa.selenium.support.ui.Select

Select select = new Select(DriverFactory.getWebDriver().findElement(By.xpath("pathway here")));

def selectedItem = select.getFirstSelectedOption().getText();

println('The item selected is ' + selectedItem)

```

OR if you just want to ensure it is correct:

`WebUI.verifyOptionSelectedByLabel(findTestObject('to'), 'your Selected Text', false, 10)`

---

<div class="post-metadata">

**Author:** ![xupacabra](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/xupacabra/32/15043_2.png) [@xupacabra](https://forum.katalon.com/u/xupacabra)\
**Post date:** [November 24, 2020, 3:05am UTC](https://forum.katalon.com/t/how-print-a-selected-item-in-drop-down/49450/4 "2020-11-24T03:05:57Z")

</div>

thank you guys  
I read everything and decided to take a test  
I got it as follows:

import org.openqa.selenium.By  
import org.openqa.selenium.support.ui.Select  
import com.kms.katalon.core.webui.driver.DriverFactory

Select select = new Select(DriverFactory.getWebDriver().findElement(By.xpath("//select[@id=‘myDropdown’]")))  
String MyLabel = select.getFirstSelectedOption().getText()

Source: [How to get text of the selected option in the dropdown](http://forum.katalon.com/t/how-to-get-text-of-the-selected-option-in-the-dropdown/12389/5)

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [November 24, 2020, 4:53pm UTC](https://forum.katalon.com/t/how-print-a-selected-item-in-drop-down/49450/5 "2020-11-24T16:53:51Z")

</div>

That’s probably where I found the code. I just store all the tidbits in my wiki for later lookup (maybe I should keep the link too). What I wanted to also say is if you have the **id** of the element, then instead of using xpath, you can use another form of the statement:

`findElement(By.id('myDropdown')))`

---

<div class="post-metadata">

**Author:** ![xupacabra](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/xupacabra/32/15043_2.png) [@xupacabra](https://forum.katalon.com/u/xupacabra)\
**Post date:** [November 25, 2020, 1:40am UTC](https://forum.katalon.com/t/how-print-a-selected-item-in-drop-down/49450/6 "2020-11-25T01:40:58Z")

</div>

Hummm cool
